我有以下字符串:
The service(s), foo bar我有一个正则表达式,检查字符串中是否包含“The”和“service(s)”字样。 我应该用反斜杠转义括号,但它似乎不起作用。 我必须使用这个正则表达式的逻辑结构。 你能帮我解决逃跑问题吗?
不工作:
(^(?=.*\b(?i)The(?-i)\b)(?=.*\b(?i)service\(s\)(?-i)\b).*$)目标语言是C#。
I have the following string:
The service(s), foo barI have a regex that checks if the words 'The' and 'service(s)' are contained within the string. 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. Can you help me fix the escaping?
Not working:
(^(?=.*\b(?i)The(?-i)\b)(?=.*\b(?i)service\(s\)(?-i)\b).*$)Target language is C#.
最满意答案
service(s)结束括号断言下一个立即位置是非单词边界。 所以你不需要last \b标记,因为你可能意味着一个非字边界\B 我认为您不需要设置和取消设置不区分大小写的修饰符:
(?i)(?=.*\bThe\b)(?=.*\bservice\(s\)\B).*$Closing parenthesis in service(s) asserts that next immediate position is a non-word boundary. So you don't need last \b token since you possibly meant a non-word boundary \B. I don't think you need to set and unset case-insensitive modifier either:
(?i)(?=.*\bThe\b)(?=.*\bservice\(s\)\B).*$更多推荐
发布评论