[英]RegEx to exclude particular words
I am working on RegEx that will match a string that contains only uppercase letters and digits but not exact words ABC or XYZ or LMN.我正在研究正则表达式,它将匹配仅包含大写字母和数字但不包含精确单词 ABC 或 XYZ 或 LMN 的字符串。
^(?!ABC|XYZ|LMN)([A-Z0-9]+)$
This works for most of the cases but fails for input ABC12, XYZ8 etc.这适用于大多数情况,但输入 ABC12、XYZ8 等失败。
How can I improve this to match the requirement.我怎样才能改进它以符合要求。
I've referred RegEx to exclude a specific string constant but couldn't tackle this one.我已经提到RegEx 来排除特定的字符串常量,但无法解决这个问题。
If you are trying to match the whole string or line using ^ and $, then you can put the $ inside your negative lookahead.如果您尝试使用 ^ 和 $ 匹配整个字符串或行,那么您可以将 $ 放在负前瞻中。 This will allow ABC12 to match.
这将允许 ABC12 匹配。
^(?!(ABC|XYZ|LMN)$)([A-Z0-9]+)$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.