I'm doing swear words filter, and I want to replace words with *
for each character. But I want to replace only words and not substrings of words and also comas, dots, ... must stay on their original place.
我正在做脏话过滤器,我想用*替换每个字符的单词。但是我想要只替换单词而不是单词的子串,还要替换comas,dots,......必须保留在原来的位置。
Pleas take a look at this (working) example. In this case I'm filtering word f***
. First and second line are correctly selected, but other two aren't. In last case shout be selected all except space
's and similar in third case.
请看看这个(工作)的例子。在这种情况下,我正在过滤单词f ***。第一行和第二行是正确选择的,但其他两行则没有。在最后一种情况下,除第三种情况外,所有除了空格和类似之外都要选择呼叫。
1 个解决方案
#1
2
It doesn't really sound like regexes are well suited for solving your entire problem. It might be easier to use regexes to find the swear words and then use code to do the replacement.
它听起来并不像正则表达式非常适合解决您的整个问题。使用正则表达式查找发誓单词然后使用代码进行替换可能更容易。
\b(swearword)\b
might be what you're looking for. \b is a zero-width word boundary.
可能就是你要找的东西。 \ b是零宽度字边界。
#1
2
It doesn't really sound like regexes are well suited for solving your entire problem. It might be easier to use regexes to find the swear words and then use code to do the replacement.
它听起来并不像正则表达式非常适合解决您的整个问题。使用正则表达式查找发誓单词然后使用代码进行替换可能更容易。
\b(swearword)\b
might be what you're looking for. \b is a zero-width word boundary.
可能就是你要找的东西。 \ b是零宽度字边界。