我要匹配以下正则表达式:
<string attribute=b>x</string> is matched by : (?<range3>[\w\d\-\:]+)[ ]*=[ ]*[\w\d\-\:]+
<string attribute='b'>x</string> is matched by (?<range1>[\w\d\-\:]+)[ ]*=[ ]*'[^']*'
<string attribute="b">x</string> is matched by (?<range2>[\w\d\-\:]+)[ ]*=[ ]*"[^"]*"
这工作正常,但以下也匹配:
<string>attribute=b</string>
<string>attribute='b'</string>
<string>attribute="b"</string>
我需要使用哪些正则表达式仅匹配前三个示例?
答案 0 :(得分:1)
(?=\S+?>\w+<\S+?)(?<range3>[\w\d\-\:]+)[ ]*=[ ]*[\w\d\-\:]+
添加了一个积极的预测,以检查&gt; x&lt; .Works now。