Jeffro Posted June 11, 2011 Share Posted June 11, 2011 I have different strings, all of which will always be different but each string will always have one instance of /123/ (where 123 could always be different text). How can I capture the 2 forward slashes with the 3 letter (or number) text in the middle? Example: string1 = "domain.com/abc/and-more-text.html" I just want /abc/ from the above (but abc might always be different as will the surrounding text except for domain.com which the 5 characters I'm grabbing will always immediately follow) Thank you. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted June 11, 2011 Share Posted June 11, 2011 ~/[^/]{3}/~ Quote Link to comment Share on other sites More sharing options...
Jeffro Posted June 11, 2011 Author Share Posted June 11, 2011 Thanks for the reply. I think that would work fine if my current string already had that contained in it but it doesn't. Is there a way to say "Give me the next 5 characters following $mystring ?" Sorry if this is a dumb question. I'm not much good at php.. just use it for the occasional hack on my sites. Thanks much. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted June 11, 2011 Share Posted June 11, 2011 so you just want the first 5 characters after domain.com ? Quote Link to comment Share on other sites More sharing options...
Jeffro Posted June 11, 2011 Author Share Posted June 11, 2011 so you just want the first 5 characters after domain.com ? Yes. I guess that would be easier that what I was originally suggesting. I got some sleep so I'm seeing clearer. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted June 11, 2011 Share Posted June 11, 2011 preg_match('~^domain\.com(.{5})~', $string1, $matches); echo $matches[1]; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.