简体   繁体   English

正则表达式匹配括号

[英]Regex match parenthesis

I have the following string: 我有以下字符串:

The service(s), foo bar

I have a regex that checks if the words 'The' and 'service(s)' are contained within the string. 我有一个正则表达式,用于检查字符串中是否包含单词“ The”和“ service(s)”。 I'm supposed to escape the brackets with backslash, but it does not seem to work. 我应该用反斜杠转义,但它似乎不起作用。 I must use the logical structure of this Regex. 我必须使用此Regex的逻辑结构。 Can you help me fix the escaping? 您能帮我解决转义吗?

Not working: 无法运作:

(^(?=.*\b(?i)The(?-i)\b)(?=.*\b(?i)service\(s\)(?-i)\b).*$)

Target language is C#. 目标语言是C#。

Closing parenthesis in service(s) asserts that next immediate position is a non-word boundary. service(s)右括号表示下一个直接位置是一个非单词边界。 So you don't need last \\b token since you possibly meant a non-word boundary \\B . 因此,您不需要最后一个\\b令牌,因为您可能希望使用非单词边界\\B I don't think you need to set and unset case-insensitive modifier either: 我认为您无需设置和取消设置不区分大小写的修饰符:

(?i)(?=.*\bThe\b)(?=.*\bservice\(s\)\B).*$

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

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