CosminO
CosminO

Reputation: 5226

Regex selecting by exclusion

("<?xml version=\"1.0\" standalone=\"yes\"?>  <DATAPACKET Version=\"2.0\" version dada Version

Let's say I have this sample text and I want to select only the version or Version words which are not preceded by the xml and DATAPACKET tags.

So far I have:

((\<?xml |\<DATAPACKET )(v|V)ersion) 

which selects the ones that I don't want to see. How do I go from here to selecting the other ones

with (\<?xml |\<DATAPACKET )?[v|V]ersion I can select all of the items, both needed and the ones that do not qualify, but I need to somehow exclude the 2 selections which have the tags part.

Upvotes: 0

Views: 55

Answers (1)

Tim Pietzcker
Tim Pietzcker

Reputation: 336128

Try the following (in Notepad++):

(?<!<\?xml\s|<DATAPACKET\s)\b[vV]ersion\b

This only works if there's exactly one whitespace character before Version; that's a limitation of the regex engine that Notepad++ uses.

In Visual Studio 2010 or higher, that limitation is removed:

(?<!<\?xml\s+|<DATAPACKET\s+)\b[vV]ersion\b

would work there.

Upvotes: 1

Related Questions