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
1 Answer
Reset to default 6How 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条)