Question

I have a string like the following

this <b>is <i>a sample</i> string</b> with multiple <b>words and some</b> keywords <b>and partially formatted</b> text.

I need to get the between <b> and </b> where no nested <i> </i> tags. That is I need "words and some" as first match and "and partially formatted" as second match.

Était-ce utile?

La solution

use a regular expression like this :

<b>(?![^}]*(<i>|<\/i>))([^}]+?)<\/b>

demo here : http://regex101.com/r/zM1zO6

you will get the results in the second match group

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top