Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对一个简单的正则表达式有一点问题。
我想要一个正则表达式来匹配这个简单的字符串(在 xml 文件中),其中 wsse: 可以是可选的,尤其是这样的:< wsse:Username >(wsse 是可选的)。
你可以帮帮我吗?
提前感谢您的帮助!
这将匹配用户名:
<(?:wsse:)?([^>]+)>
编辑: 并允许冒号前的任何字符串:
<(?:[^:]+:)?([^>]+)>
虽然不是理想的解决方案(因为您确实应该使用 XML 解析器或 XSLT 来解析 XML),但以下内容对您有用:
<((wsse:)?Username)>(.*)(</\1>)
每场比赛还将返回 4 个组。
第 3 组将返回标签内的实际用户名