I'm trying to find a way to find and replace in Notepad++ and I can't figure out how to do the regex that would allow me to do so. I need to find all
<Element
Attribute1="<!--Any one letter-->34_<!--Anything-->"
<!--Multiple Attributes on multiple lines-->
<!--Until-->
AttributeToMatch="Value"
<!--Multiple Attributes on multiple lines--> />
I want the following:
<Element
Attribute1="<!--Any one letter-->34_<!--Anything-->"
<!--Multiple Attributes on multiple lines-->
<!--Until-->
AttributeToMatch="NewValue"
<!--Multiple Attributes on multiple lines--> />
I need to be able to replace only the "SpecificValue" with another Value for hundreds of elements so I wanted to find a way to do it more quickly and efficiently then doing it manually.
So far I came up with:
Which doesn't work (nothing is found) and I don't understand why. Thanks
Alright, I haven't tried this in Notepad++ specifically, but give it a go.
/\<Element[\S\s]*Attribute1\=\".*34_.*\"[\S\s]*AttributeToMatch\=\"([^\"]*)\"[\S\s]*\/\>[\S\s]*(?=\<Element)/igm
The igm
is just notation that means it should be case insensitive, global, and multiline. Strip that off for Notepad++ probably.
You'll also need to be able to replace capture group $1 with your new value. Again, I'm not sure how that works in Notepad++.
The [\\S\\s]*
groups match anything including newlines.
Finally, it avoids capturing more than one element at a time with a lookahead for <Element
. It could also match the end of file if Notepad++ supports it, or add a fake
(My gut feeling remains that you'll have an easier time just parsing the XML and making the changes that way.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.