WorldDrknss Posted March 26, 2019 Share Posted March 26, 2019 I'm trying to match <!-- FOR 5 --> Some HTML content <!-- END FOR --> Using preg_match \<\!\-\- FOR (\d+) \-\-\>(.*)\<\!\-\- END FOR \-\-\> Doesn't work since they are on different lines. Quote Link to comment https://forums.phpfreaks.com/topic/308513-matching-between-comment-lines/ Share on other sites More sharing options...
requinix Posted March 26, 2019 Share Posted March 26, 2019 First you need to learn that < ! - > are not special characters. Escaping them with backslashes makes you look a bit silly. Then learn about the /x and /s flags. One of them is what you need. The other is me trying to trick you into learning something unrelated. Then test your regular expression with some HTML content that contains two or more of those FOR/END FORs and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/308513-matching-between-comment-lines/#findComment-1565616 Share on other sites More sharing options...
Psycho Posted July 3, 2019 Share Posted July 3, 2019 Also, you need to look into how to make your capturing conditions "greedy" or "non greedy". By default, matches will be greedy. So a condition such as "A(.*)B" with the string "A1B A2B A3B" would find one match "1B A2B A3" - everything form the first "A" to the last "B". If you wanted to find all the values between each set of A/B, then you need make the match non-greedy - "A(.*?)B" Quote Link to comment https://forums.phpfreaks.com/topic/308513-matching-between-comment-lines/#findComment-1568117 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.