2011-06-22 172 views
-3

我必須編寫一個檢查器,它使用正則表達式排除以@ tag5.com和@ tagfive.com之類的特定電子郵件結尾的內容。由於我沒有真正使用過正則表達式,所以不知道該如何做到這一點,希望有人能告訴我如何或指向正確的方向。正則表達式排除XML中的某些字符串

只需要知道什麼正則表達式使用更具體。

- 編輯 -

納米我發現了一個更好的解決辦法,以我是有和沒有處理正則表達式的問題。

+0

XML在哪裏進來? –

+0

它是爲gmail上下文小工具創建的清單。基本上,您必須創建一個正則表達式,用於在電子郵件的不同部分上搜索以確定何時在每封郵件中顯示小工具。 – Novazero

+0

我以爲這是正確的正則表達式^(?!。*?@ tag5 \ .com)(?=。*?@ tagfive \ .com)。*?$ – Novazero

回答

1

這似乎只有這樣,才能頒佈消極和積極的斷言是這樣的:

正則表達式:'(?=^(?:([email protected]\.com).)*$)(?=.*@tagfive\.com)'

目標:'[email protected]@tagfive.comasdf!'

以來,使用(?!.*@tag5\.com)將匹配任何東西。

(?=^   # Positive lookahead at start of line 
     (?:    # Group 
      (?!    # Negative lookahead assertion 
       @tag5\.com  # Can't be @tag5.com at this position 
      )     # End assertion 
      .     # This character is ok, take it 
     )*     # End group, do many times until .. 
    $    # End of line 
)     # End of positive lookahead assertion 
    (?=    # Meanwhile, back at the start of line, positive lookahead 
    .*     # Keep going until we find: 
    @tagfive\.com  # this (and it MUST be here) 
)     # End of positive lookahead 
0

這應該工作:@tag(5|five)\.com$

相關問題