I'm looking for one regular expression that could match a string for three specific cases in a xml file:
我正在寻找一个正则表达式,它可以匹配xml文件中三个特定情况的字符串:
- : Double-quotes surrounding a string.
- : A string surrounded by the characters greater than and Less Than.
- : A string surrounded by the characters ; and &.
:字符串周围的双引号。
:由大于和小于的字符包围的字符串。
:由字符包围的字符串;和&。
Example:
- "MyString" - Valid match
- >MyString< - Valid match
- ;MyString& - Valid match
“MyString” - 有效匹配
> MyString < - 有效匹配
; MyString& - 有效匹配
Other possible combinations are invalid match.
其他可能的组合是无效匹配。
“MyString < - 无效匹配
; MyString“ - 无效匹配
2 个解决方案
#1
Try this: ("MyString")|(>MyString<)|(;MyString&)
试试这个:(“MyString”)|(> MyString <)|(; MyString&)
#2
You cannot use regex to parse xml, it is not a regular grammar. Use an xml parser, seriously.
你不能使用正则表达式来解析xml,它不是常规语法。严肃地使用xml解析器。
When you're using your parser to inspect text node values then and only then you might want to use (\".*?\")|(>.*?<)|(;.*?&)
but I doubt you'll find the problem is framed the same way. >MyString< is very suspicious.
当您使用解析器检查文本节点值时,您可能只想使用(\“。*?\”)|(>。*?<)|(;。*?&)但我怀疑你我会发现问题的框架方式相同。 > MyString <非常可疑。< p>
#1
Try this: ("MyString")|(>MyString<)|(;MyString&)
试试这个:(“MyString”)|(> MyString <)|(; MyString&)
#2
You cannot use regex to parse xml, it is not a regular grammar. Use an xml parser, seriously.
你不能使用正则表达式来解析xml,它不是常规语法。严肃地使用xml解析器。
When you're using your parser to inspect text node values then and only then you might want to use (\".*?\")|(>.*?<)|(;.*?&)
but I doubt you'll find the problem is framed the same way. >MyString< is very suspicious.
当您使用解析器检查文本节点值时,您可能只想使用(\“。*?\”)|(>。*?<)|(;。*?&)但我怀疑你我会发现问题的框架方式相同。 > MyString <非常可疑。< p>