Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top