简体   繁体   English

Javascript / REGEX:删除以字符串中以空格分隔的特定字母(单词)开头的特定文本(单词)

[英]Javascript / REGEX: 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: 我知道使用Regex可以很快完成此操作:

I got string like: 我有这样的字符串:

"Alpha OmegaS Sheol Gehena GSSaga Serekali" “ Alpha OmegaS Sheol Gehena GSSaga Serekali”

I wanna remove words that Starts with s. 我想删除以s开头的单词。

So I should have: 所以我应该有:

"Alpha OmegaS Gehena GSSaga" “阿尔法欧米茄Gehena GSSaga”

What have I tried? 我尝试了什么?

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

The thing is I understand REGEX very well, but somehow REGEX does NOT understand me. 问题是我对REGEX非常了解,但是REGEX却不了解我。

Any help is appreciated. 任何帮助表示赞赏。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript正则表达式-分割字符串,单词之间用空格,逗号和括号分隔 - Javascript regex - Split string with words separated from spaces, commas and parenthesis Javascript 使用正则表达式删除特定文本 - Javascript delete specific text with Regex Javascript:提取字符串中以特定字符开头的单词 - Javascript : Extract words starting with specific character in a string Javascript正则表达式只匹配以特定特殊字符开头的单词 - Javascript regex match only words starting with a specific special character 通过Javascript正则表达式选择所有不是特定单词的单词吗? - Select all words that are not a specific word, via Javascript regex? Javascript 正则表达式搜索 ArrayList 以获取特定单词并在之前/之后打印单词 - Javascript regex search ArrayList for specific word and print words before/after Javascript正则表达式获取除特定单词之外的任何单词列表,但也获取另一个组中的特定单词 - Javascript Regex to get list of any words except a specific word but also get that specific word in another group Javascript - 如何在文本字符串中设置特定单词的样式? - Javascript - How to style specific word in a string of text? 正则表达式用逗号分隔3个字母的单词 - Regex for comma separated 3 letter words Javascript正则表达式在逗号分隔的字符串中拆分单词 - Javascript regex splitting words in a comma separated string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM