ShaolinF Posted August 29, 2010 Share Posted August 29, 2010 Hi Guys I am trying to get some content between some div tags but cannot do so thus far. Code and regex below: <blockquote class="postcontent restore "> content here </blockquote> Regex: /<blockquote class=\"postcontent restore \">(.*?)<\/blockquote>/ Returns nothing.. Any ideas on where I am going wrong ? Quote Link to comment https://forums.phpfreaks.com/topic/212022-regex-and-html-parsing/ Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 You're close, you just need to add the m modifier to make the dot match newlines. /<blockquote class=\"postcontent restore \">(.*?)<\/blockquote>/m Quote Link to comment https://forums.phpfreaks.com/topic/212022-regex-and-html-parsing/#findComment-1104944 Share on other sites More sharing options...
ShaolinF Posted August 29, 2010 Author Share Posted August 29, 2010 Thanks but that didnt work either Quote Link to comment https://forums.phpfreaks.com/topic/212022-regex-and-html-parsing/#findComment-1104946 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 Are you sure you're trying it with the exact example you provided us? Because it works for me. Note that you have a space on this line: <blockquote class="postcontent restore "> Within the class. You probably want to remove that from both the HTML and the pattern. Quote Link to comment https://forums.phpfreaks.com/topic/212022-regex-and-html-parsing/#findComment-1104948 Share on other sites More sharing options...
ShaolinF Posted August 29, 2010 Author Share Posted August 29, 2010 Yes, I copy/pasted it into my editor. Bare in mind the 'content here' bit being wrapped in the blockquotes will hold data pulled from a WYSIWYG editor. BTW, the space is meant to be there. Quote Link to comment https://forums.phpfreaks.com/topic/212022-regex-and-html-parsing/#findComment-1104953 Share on other sites More sharing options...
cags Posted August 29, 2010 Share Posted August 29, 2010 It's the s modifier that will make the . match newline characters, not the m. Quote Link to comment https://forums.phpfreaks.com/topic/212022-regex-and-html-parsing/#findComment-1105012 Share on other sites More sharing options...
Alex Posted August 29, 2010 Share Posted August 29, 2010 Yeah, cags is right. I was confusing PCRE regular expressions with Ruby regular expressions where the m modifier makes newlines be treated as regular characters (and thus be matched by the period). Quote Link to comment https://forums.phpfreaks.com/topic/212022-regex-and-html-parsing/#findComment-1105016 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.