0

我知道这可以用正则表达式快速完成:

我得到了这样的字符串:

"阿尔法欧米茄地狱 Gehena GSSaga Serekali"

我想删除以 s 开头的单词。

所以我应该有:

“Alpha OmegaS Gehena GSSaga”

我尝试了什么?

就像是:str.replace(/^\\S/,"") //This NO GOOD.

问题是我非常了解 REGEX,但不知何故 REGEX 不了解我。

任何帮助表示赞赏。

4

1 回答 1

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
于 2013-09-03T11:03:29.720 回答