正则表达式删除空格并匹配确切的单词(regex remove whitespaces and match exact words)

编程入门 行业动态 更新时间:2024-10-18 22:33:21
正则表达式删除空格并匹配确切的单词(regex remove whitespaces and match exact words)

我真的不知道正则表达式,所以有人可以举例说明如何修复这个正则表达式http://rubular.com/r/UdzYMJc9iE :

/\b([stack over flow]+)+\b/

不匹配空格并且只匹配精确的单词(堆栈匹配ac作为单词,我想只匹配堆栈),tia。

我希望当我们'norem etiam nam'只匹配正则表达式中的这三个单词时,没有空格。

我尝试使用\ s,\ S,/ x,但没有结果..

I'm don't know regex really well, so can someone give me example how to fix this regex http://rubular.com/r/UdzYMJc9iE:

/\b([stack over flow]+)+\b/

not to match whitespaces and to match only exact words (stack matches ac as word, I want to match only stack), tia.

I want when we have 'lorem etiam nam' to match only these exact 3 words from the regex, without spaces.

I tried using \s, \S, /x, but there was no result..

最满意答案

如果您只想匹配三个选项,请使用| 语法,并将它们分组为普通括号:

/\b(stack|over|flow)+\b/

不确定+或您想要匹配的内容。

If you only want to match three alternatives, use the | syntax, and group them into normal parenthesis:

/\b(stack|over|flow)+\b/

Not sure about the + or what exactly you wanted to match.

更多推荐

本文发布于:2023-08-06 05:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444526.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空格   确切   单词   正则表达式   regex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!