我想匹配除给定单词之外的所有内容,因此给出以下列表:
@H_403_1@wordOne
wordTwo/xy/z
word-three
word-four/lots/of/stuff
我可以使用这个正则表达式匹配除wordOne之外的所有内容:
@H_403_1@(?!wordOne)\b.+ ==> wordTwo/xy/z word-three word-four/lots/of/stuff但是,如果我想匹配除了包含连字符/破折号的单词之外的所有内容,则相同的正则表达式不起作用,因为连字符不是单词边界的一部分 – 这是[a-zA-Z0-9_]
例如
@H_403_1@some-regexp(word-four) ==> wordOne wordTwo/xy/z word-three和
@H_403_1@some-regexp(word-four and word-three) ==> wordOne wordTwo/xy/z
我可以看到你在示例中每行定义一个单词.在这种情况下,这个正则表达式应该适合你:
@H_403_1@^(?:(?!word-four|word-three).)*$
它会跳过包含四字或三字的单词.
根据你的例子:
@H_403_1@^(?:(?!wordOne).)*$ ==> wordTwo/xy/z word-three word-four/lots/of/stuff ^(?:(?!word-four).)*$ ==> wordTwo/xy/z word-three word-four/lots/of/stuff ^(?:(?!word-four|word-three).)*$ ==> wordOne wordTwo/xy/z在rubular上看到它.