admin管理员组文章数量:1403500
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
本文标签:
版权声明:本文标题:JavascriptREGEX: Delete a specific Text (word) starting with a specific letter inside a String with words separated by spaces - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744345876a2601754.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论