2

I want to search a document for the following string

<whoName>[substring]</whoName>

where substring != "self"

so

<whoName>other</whoName> 

would pass.

but

<whoName>self</whoName> 

would fail

veta
  • 716
  • 9
  • 22

3 Answers3

4

You can use this negative lookahead based regex:

<(whoName)>(?!self\s*<).*?<\/\1>

RegEx Demo

Regex breakup:

<(whoName)>  # Match <whoName> and capture it ($1)
(?!self\s*<) # Negative lookahead that means current position is not followed by literal 
             # self followed by 0 or more spaces and <
.*?          # Match 0 or more characters (non-greedy)
<\/\1>       # Match closing tag using back-reference to captured group #1
anubhava
  • 761,203
  • 64
  • 569
  • 643
1

Use this regex:

^<whoName>((?!self<).)*</whoName>

Tested in notepad++ and regex101

Santiago
  • 1,744
  • 15
  • 23
1

You can find the solution here.

You could use something like

<whoName>(?!self)[a-z0-9]*<\/whoName>

(try this out here: https://regex101.com/r/vW8sP3/1).

As you can imagine the relevant part is (?!self).

Community
  • 1
  • 1
michele
  • 169
  • 4