pnvn
pnvn

Reputation: 488

Finding XML nodes in which an attribute's value contains a specific character

I have an XML file (many MB in size), which I view using Notepad++. Many of the XML nodes are of the form:

<ItemInfo ID="something" Name="some name1" />

The ID attribute can have values containing special characters like semicolon (;).

Example:

<ItemInfo ID="something" Name="some name1" />
<ItemInfo ID="some;thing;" Name="some name2" />
<ItemInfo ID="some;thing" Name="some name3" />

Now, I want to go over all occurrences (using regex in the Find feature) in which the value of the ID attribute contains one or more semicolons (;).

After seeing some example on the web, I tried the following with no success.

"<ItemInfo ID="".*";

"<ItemInfo ID=""(.*)";

"<ItemInfo ID=\"".*";""\""

In essence, I'd like to find all strings:

containing a specific character,

starting with some fixed text, and

ending with some fixed text.

Can anyone please give a solution or point me in the right direction? I think I'd have to do the same kind of operation frequently in the future.

Thanks in advance.

Upvotes: 0

Views: 3129

Answers (2)

sean_m
sean_m

Reputation: 1584

Give this a shot:

.*ID=.*[;].*Name=.*

More info on how notepad++ does regex is here

Upvotes: 1

Jo&#227;o Silva
Jo&#227;o Silva

Reputation: 91349

Try the following to find all strings which contain a ; in the ID:

<ItemInfo ID="[^"]*;[^"]*

To find strings having an ID that starts with some fixed text:

<ItemInfo ID="text[^"]*"

And to find strings having an ID that end with some fixed text:

<ItemInfo ID="[^"]*text"

Upvotes: 1

Related Questions