我正在寻找一种方法来删除包含这些字符的单词或数字:*
或 .
。
我尝试编写自己的正则表达式,但我真的搞不懂。例如
The sh*t just hit the fan 102.7 and google.com
应该导致:
The just hit the fan and
只是一个随机句子,但它应该删除单词 sh*t
、102.7
和 google.com
。
它是否会留下双空格并不重要。
在此先致谢,感谢您的帮助!
最佳答案
result = subject.replace(/\S*[.*]\S*/g, "");
应该这样做。
解释:
\S* # match any number of non-whitespace characters
[.*] # match either a dot or an asterisk
\S* # match any number of non-whitespace characters
关于javascript - 删除包含星号或点的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8313053/