insomnomaniac Posted July 15, 2010 Share Posted July 15, 2010 Hi All, I'm new to regex and need some help. I'm trying to parse through a web page to find all the strings below that are separated by new lines: <h3 class="listing-price"> $21,555 </h3> $pattern = 'XXX'; preg_match_all($pattern, $content, $output); Thanks! Link to comment https://forums.phpfreaks.com/topic/207886-help-with-regular-expressions-that-include-new-lines/ Share on other sites More sharing options...
premiso Posted July 15, 2010 Share Posted July 15, 2010 What do you want, the dollar amount? The 's' modifier will treat the string as one long string / ignores new lines (if my terminology is correct). $pattern = '~class="listing-price">(.*)</h3>~isU'; May give you what you are after, not really sure as you did not specify your expected output.. Link to comment https://forums.phpfreaks.com/topic/207886-help-with-regular-expressions-that-include-new-lines/#findComment-1086744 Share on other sites More sharing options...
Zane Posted July 15, 2010 Share Posted July 15, 2010 use the multiline modifier in your regex pattern $pattern = "/XXX/m" the m is the modifier, it goes after the delimiters (the slashes) Link to comment https://forums.phpfreaks.com/topic/207886-help-with-regular-expressions-that-include-new-lines/#findComment-1086745 Share on other sites More sharing options...
insomnomaniac Posted July 15, 2010 Author Share Posted July 15, 2010 What do you want, the dollar amount? The 's' modifier will treat the string as one long string / ignores new lines (if my terminology is correct). $pattern = '~class="listing-price">(.*)</h3>~isU'; May give you what you are after, not really sure as you did not specify your expected output.. Sorry about that...Yes, I'm trying to get the dollar amount without the '$' symbol. So in my example I'm trying get '21,555'. Your pattern works but it includes the '$' with a space in front of it. Thanks! Link to comment https://forums.phpfreaks.com/topic/207886-help-with-regular-expressions-that-include-new-lines/#findComment-1086750 Share on other sites More sharing options...
premiso Posted July 15, 2010 Share Posted July 15, 2010 You couldn't figure out the new pattern? el sigh. $pattern = '~class="listing-price">.*\$(.*)</h3>~isU'; Link to comment https://forums.phpfreaks.com/topic/207886-help-with-regular-expressions-that-include-new-lines/#findComment-1086756 Share on other sites More sharing options...
insomnomaniac Posted July 15, 2010 Author Share Posted July 15, 2010 You couldn't figure out the new pattern? el sigh. $pattern = '~class="listing-price">.*\$(.*)</h3>~isU'; Thank you sir! Link to comment https://forums.phpfreaks.com/topic/207886-help-with-regular-expressions-that-include-new-lines/#findComment-1086758 Share on other sites More sharing options...
ZachMEdwards Posted July 16, 2010 Share Posted July 16, 2010 The 's' modifier will make the . (dot) match newlines. Link to comment https://forums.phpfreaks.com/topic/207886-help-with-regular-expressions-that-include-new-lines/#findComment-1087215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.