1

In my document I have

<Country>US</Country>
<Country>PR</Country>

Between the

<country>

and

</country> 

I want to find ANYTHING except for US and PR.

For example

<country>US</country>   =  ignore
<country>PR</country>   =  ignore

<country>UP</county>    =  match found

What I have is

Pattern = "<Country>(.*?[^USPR].*?)</Country>"

but this ignores strings like

<Country>UP</Country>  

Not sure how to write allowing only 2 options between the tags.. US and PR only.

user2150312
  • 123
  • 11

2 Answers2

3

This should work.

<country>(?!(US|PR))(.*?)</country>

Matches the opening <country> tag not followed by US or PR. Then goes on to match anything before the closing </country> tag.

Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89
0

Try this one:

(?<=<Country>(?!US|PR)).*?(?=</Country>)
Alex Filipovici
  • 31,789
  • 6
  • 54
  • 78