2015-09-05 49 views

回答

3

您可以使用該負前瞻基於正則表達式:

<(whoName)>(?!self\s*<).*?<\/\1> 

RegEx Demo

正則表達式的分手:

<(whoName)> # Match <whoName> and capture it ($1) 
(?!self\s*<) # Negative lookahead that means current position is not followed by literal 
      # self followed by 0 or more spaces and < 
.*?   # Match 0 or more characters (non-greedy) 
<\/\1>  # Match closing tag using back-reference to captured group #1 
+0

這個正則表達式不匹配自拍或任何以自我開頭的子字符串 – Santiago

+0

是的,我正在更新和寫更多的細節。請立即檢查更新的答案。 – anubhava

1

使用這個表達式:

^<whoName>((?!self<).)*</whoName> 

經測試,在記事本+ +和regex101

1

你可以找到解決辦法here

您可以使用類似

<whoName>(?!self)[a-z0-9]*<\/whoName> 

(這裏嘗試了這一點:https://regex101.com/r/vW8sP3/1)。

正如你可以想象的相關部分是(?!self)