JavascriptREGEX: 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:I got string like: "Alpha OmegaS Sheol Gehena GSSaga Se

I know this can quickly be done with Regex:

I got string like:

"Alpha OmegaS Sheol Gehena GSSaga Serekali"

I wanna remove words that Starts with s.

So I should have:

"Alpha OmegaS Gehena GSSaga"

What have I tried?

Something like: str.replace(/^\\S/,"") //This NO GOOD.

The thing is I understand REGEX very well, but somehow REGEX does NOT understand me.

Any help is appreciated.

I know this can quickly be done with Regex:

I got string like:

"Alpha OmegaS Sheol Gehena GSSaga Serekali"

I wanna remove words that Starts with s.

So I should have:

"Alpha OmegaS Gehena GSSaga"

What have I tried?

Something like: str.replace(/^\\S/,"") //This NO GOOD.

The thing is I understand REGEX very well, but somehow REGEX does NOT understand me.

Any help is appreciated.

Share Improve this question asked Sep 3, 2013 at 11:01 ErickBestErickBest 4,6905 gold badges32 silver badges45 bronze badges 2
  • You specified a lower case "s" where as the text sample you give only contains words beginning with an uppercase "S". Are you looking to remove words starting with both lower and uppercase "s"? – Lix Commented Sep 3, 2013 at 11:09
  • insensitively targeting the case will be a prudent move... – ErickBest Commented Sep 3, 2013 at 11:16
Add a ment  | 

1 Answer 1

Reset to default 6

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744345876a4569679.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信