我知道这可以通过Regex快速完成:
我的字符串如下:
“Alpha OmegaS Sheol Gehena GSSaga Serekali”
我想删除以s开头的单词。
所以我应该:
“Alpha OmegaS Gehena GSSaga”
我尝试了什么?
类似于:str.replace(/^\\S/,"") //This NO GOOD.
事情是我很了解REGEX,但不知何故REGEX不理解我。
感谢任何帮助。
答案 0 :(得分:6)
怎么样:
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