lemmin Posted January 29, 2010 Share Posted January 29, 2010 Suppose I had some input that looked something like this: [Title1] any random characters <match1> <match2> maybe more random <match3> [/Title1] [Title2] any random characters <match4> <match5> maybe more random <match6> [/Title2] [Title3] any random characters <match7> <match8> maybe more random <match9> [/Title3] If all "match" strings were matched by my regex, how could I only match the ones inside of a specific area, such as the "Title2" area. Do I need to extract that area first and then perform the regex? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/190293-multiple-matches-inside-a-match/ Share on other sites More sharing options...
cags Posted January 29, 2010 Share Posted January 29, 2010 That would be the easiest approach yes. Quote Link to comment https://forums.phpfreaks.com/topic/190293-multiple-matches-inside-a-match/#findComment-1003935 Share on other sites More sharing options...
lemmin Posted January 29, 2010 Author Share Posted January 29, 2010 Thanks. I was just thinking that it would be more efficient if I could do it in one single preg_match() call. I guess if I can't I will just do it that way. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/190293-multiple-matches-inside-a-match/#findComment-1003940 Share on other sites More sharing options...
cags Posted January 29, 2010 Share Posted January 29, 2010 It can be done in one match you could simply use something along the lines of... '#\[Title1\].*?<match>.*?\[/Title1\]#' Quote Link to comment https://forums.phpfreaks.com/topic/190293-multiple-matches-inside-a-match/#findComment-1003993 Share on other sites More sharing options...
lemmin Posted February 2, 2010 Author Share Posted February 2, 2010 Wouldn't that only match one of the matches in that section? I would be trying to match more than one occurrence inside of that title section. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/190293-multiple-matches-inside-a-match/#findComment-1005760 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.