Javascript/REGEX:删除以字符串中以空格分隔的单词开头的特定文本(单词) [英] Javascript / REGEX: Delete a specific Text (word) starting with a specific letter inside a String with words separated by spaces
本文介绍了Javascript/REGEX:删除以字符串中以空格分隔的单词开头的特定文本(单词)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道使用Regex可以很快做到这一点:
I know this can quickly be done with Regex:
我得到了像这样的字符串:
I got string like:
"Alpha OmegaS Sheol Gehena GSSaga Serekali"
"Alpha OmegaS Sheol Gehena GSSaga Serekali"
我想删除以s开头的单词.
I wanna remove words that Starts with s.
所以我应该有:
"Alpha OmegaS Gehena GSSaga"
"Alpha OmegaS Gehena GSSaga"
我尝试了什么?
类似的东西: str.replace(/^ \\ S/,")//这不好.
问题是我对REGEX非常了解,但是REGEX却不了解我.
The thing is I understand REGEX very well, but somehow REGEX does NOT understand me.
感谢您的帮助.
推荐答案
怎么样:
str.replace(/\bs\S+/ig,"")
说明:
NODE EXPLANATION
----------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
----------------------------------------------------------------------
s 's'
----------------------------------------------------------------------
\S+ non-whitespace (all but \n, \r, \t, \f,
and " ") (1 or more times (matching the
most amount possible))
----------------------------------------------------------------------
i is for case-insensitive
g is for global
这篇关于Javascript/REGEX:删除以字符串中以空格分隔的单词开头的特定文本(单词)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文