Reputation: 3659
Trying to create a pattern that includes an or condition.
$pattern["body"]='/(<\/a><\/li><\/ul><\/div><p>|<h2>)(.*)<div class="like">/s';
The pattern should recognize any text between a series of "<\/a><\/li><\/ul><\/div><p>
" or a "<h2>
" as the beginning delimiter, but apparently the or condition does not work in this case.
Anyone can offer a hint for the correct syntax!? I am striving for 1 hour and I have lost the focus and patience in this rule.
THank you in advance.
Upvotes: 0
Views: 98
Reputation:
This might work http://www.ideone.com/zYB1n
But, I'm no php expert.
$regex = '/(?:<\/a>\s*<\/li>\s*<\/ul>\s*<\/div>\s*<p>|<h2>)(?<Text>[\S\s]*)(?=<div class="like">)/';
if (preg_match( $regex, $str1, $matches ))
print_r( $matches['Text'] );
Upvotes: 0
Reputation: 7035
'%(</a></li></ul></div><p>|<h2>)(.*)<div class="like">%s'
I don't have any sample data to test against but it looks like you were there. I only changed the delimiter so it wouldn't have to be escaped, I find it's easier to understand.
Upvotes: 0
Reputation: 195199
"(?<=</a></li></ul></div>|<h2>).*"
see below grep test:
kent$ echo "</a></li></ul></div>something"|grep -Po "(?<=</a></li></ul></div>|<h2>).*"
something
kent$ echo "<h2>something"|grep -Po "(?<=</a></li></ul></div>|<h2>).*"
something
Upvotes: 1