简体   繁体   English

字符串中多个字符串的正则表达式精确匹配

[英]Regex exact match of multiple strings within string

I have an string of |DOGS|MAN|CAT|我有一串 |DOGS|MAN|CAT| and I need to check that DOG and CAT exist in the string.我需要检查字符串中是否存在 DOG 和 CAT。

The input string is always split between pipes.输入字符串始终在管道之间拆分。

I have this at present:我目前有这个:

((^|, )(?=.*\|DOG|\b.$)(?=.*\|CAT\b).*$)

This almost works, if my input string was |DOG|MAN|CAT|这几乎有效,如果我的输入字符串是 |DOG|MAN|CAT| it is fine but as I have specified DOGS not DOG it should not match很好,但因为我指定了 DOGS 而不是 DOG,它不应该匹配

This RegEx might help you to create a group, where you can list all your desired target string in it using a |此正则表达式可能会帮助您创建一个组,您可以在其中使用|列出所有所需的目标字符串。 (OR), and you may not bound it from left and right, if possible: (或),并且如果可能,您不得从左到右绑定它:

\b(DOG|CAT|ANYTHING|ELSE|THAT|YOU|WISH)\b

正则表达式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM