Reputation: 726
Via a Regex, I'm trying to match the word one
, only when it's within an HTML <p>
tag.
<p>zero one two three</p>
zero one two<p>three</p>
<p>zero one <b>two</b></p><p>three</p>
<p>two</p>three one
#1 and #3 above should be matches. It feels like I need a lookahead that makes sure there is a closing </p>
tag without an opening <p>
tag that comes before it (or a lookbehind that does the opposite). But I can't seem to come up with the right expression. Any ideas are appreciated.
Upvotes: 0
Views: 57
Reputation: 67968
<p>(?:(?!<\/p>).)*(\bone\b)(?:(?!<\/p>).)*<\/p>
You can try this.Just grab the capture.See demo.
http://regex101.com/r/xT7yD8/12
Upvotes: 2
Reputation: 174706
You could try the below regex to match the string one
which is inside the <p>
tag.
\bone\b(?=(?:(?!<\/?p>).)*<\/p>)
Upvotes: 1