Regex matching an open and close tag and a certain text patterns inside that tag


Here is a sample custom tag i have from a sitemap.xml


There are many entries like this and if you see loc tag it has c=d;0=a at the end.
I want to remove all entries starting with <url> ending with </url> which contains C=D;0=A or similar patterns like that.

The following expression matched the whole of the above specified tag


but I want to match like what i had specified in the above statement.

How do we form regex to match such conditions(patterns) ?

Best Solution

Try this:


The negative lookahead guaranties that you do not match multiple nodes.

See here: rubular

Related Question