Regular expression to find and replace string in xml
I'm looking for one regex that can match a string for three specific cases in an XML file:
- : double quotes surrounding the string.
- : a string surrounded by more and less characters .
- : string surrounded by characters ; and & .
Example:
- "MyString" - Valid match
- > MyString < - Valid match
- ; MyString & - Valid match
Other possible combinations are invalid.
"MyString < - Invalid match ; MyString" - Invalid match
0
a source to share
2 answers
You cannot use regex to parse xml, it is not regex grammar. Use the xml parser, seriously.
When you use your parser to check for text node values then and only then you can use (\".*?\")|(>.*?<)|(;.*?&)
, but I doubt you find that the problem is framed in the same way. > MyString <is very suspicious.
+2
a source to share