[英]Javascript / REGEX: Delete a specific Text (word) starting with a specific letter inside a String with words separated by spaces
I know this can quickly be done with Regex: 我知道使用Regex可以很快完成此操作:
I got string like: 我有这样的字符串:
"Alpha OmegaS Sheol Gehena GSSaga Serekali" “ Alpha OmegaS Sheol Gehena GSSaga Serekali”
I wanna remove words that Starts with s. 我想删除以s开头的单词。
So I should have: 所以我应该有:
"Alpha OmegaS Gehena GSSaga" “阿尔法欧米茄Gehena GSSaga”
What have I tried? 我尝试了什么?
Something like: str.replace(/^\\\\S/,"") //This NO GOOD.
像这样: str.replace(/^\\\\S/,"") //This NO GOOD.
The thing is I understand REGEX very well, but somehow REGEX does NOT understand me. 问题是我对REGEX非常了解,但是REGEX却不了解我。
Any help is appreciated. 任何帮助表示赞赏。
How about: 怎么样:
str.replace(/\bs\S+/ig,"")
Explanation: 说明:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.