开发者

Regular Expression to Exclude Certain Strings in XML

I have to write a checker which uses regular expressions to exclude things that end with a certain email ending like @tag5.com and @tagfive.com. Not really sure how to do this since I haven't really worked a lot with regular expressions hope someone can show me how or point me in the righ开发者_如何学运维t direction.

Only need to know what regular expression to use to be more specific.

--edit--

nm I found a better solution to the problem I was having and don't have to deal with regular expressions.


It appears the only way to promulgate a negative and positive assertion is something like this:

Regex: '(?=^(?:(?!@tag5\.com).)*$)(?=.*@tagfive\.com)'

Target: '22$sAsWNoid@tag5.comaASDFsdf@tagfive.comasdf!'

Since, using (?!.*@tag5\.com) will match anything.

  (?= ^              # 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


This should work: @tag(5|five)\.com$

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜