Question

So i have searched all over for this and I cant find exactly what im looking for. Here is what im trying to do. I have an xml file with various id's with span classes that need to be removed and replaced with a new tag. Here is an example:

I have these tags:

 <span class="price" id="VARIABLE ID1">$4.99</span>
 <span class="price" id="VARIABLE ID2">$5.99</span>
 <span class="price" id="VARIABLE ID3">$5.99</span>

I want to do a find and replace to have these tags:

 <price>$4.99</price>
 <price>$5.99</price>
 <price>$6.99</price>

My research and past knowledge tells me that I open find and replace, make sure that "use regular expressions" is checked and then do this:

Find: <span class="price" id="([^<]*)">([^<]*)[[^"]*</td>

Replace: <price>$1</price>

However it doesn't work. It says no matches found. Something is wrong but I cant figure it out.

Any help would be great.

Was it helpful?

Solution

Ok so with some research and studying I found the answer. In order to achieve this you have to search for <span class="price" id="[^"]*["]"> and replace with <price>. To take this even further you could search with this>

class="[^"]*["]|id="[^"]*["]|style="[^"]*["]

Let’s break down this regular expression down piece by piece. I suggest using the table of rules provided by Adobe as reference.

sid=” – the s represent any type of space (tab, space, form/line feed). Checking for a space is important for some tags as it ensures that you are not picking up fragments of other attributes. For instance, align=” would pick up both align and valign tag attributes.

[^"]* – this matches any character except the double quote (“) character and continues to until it finds a double quote. This is because the [^"] rule is proceeded by a asterisk (*). ” – picks up the closing double quote to complete the regex.

|sclass=”[^"]”| sstyle=”[^"]”- the vertical line character (|) signifies an either/or rule. Therefore, it will find all id, class and style tags that begin and end with double quotes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top