正则表达式排除XML中的某些字符串

时间:2011-06-22 22:36:44

标签: regex xml

我必须编写一个检查程序,它使用正则表达式排除以@ tag5.com和@ tagfive.com等特定电子邮件结尾的内容。不太确定如何做到这一点,因为我没有真正用正则表达式做很多工作,希望有人能告诉我如何或指出我正确的方向。

只需知道要使用的正则表达式更具体。

- 的修改 -

nm我找到了一个更好的解决方案,解决了我遇到的问题,而且不必处理正则表达式。

2 个答案:

答案 0 :(得分:1)

似乎发布消极和积极断言的唯一方法是这样的:

正则表达式:'(?=^(?:(?!@tag5\.com).)*$)(?=.*@tagfive\.com)'

目标:'22$sAsWNoid@tag5.comaASDFsdf@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

答案 1 :(得分:0)

这应该有效:@tag(5|five)\.com$

相关问题