How do I use regular expressions to clean up a few of the sensitive words that appear in an article, and use underscores to connect the sensitive words that appear?
There may be multiple groups of sensitive words, and the number of occurrences of each group is random.
Like an article like this
Blog Park has a lot of good blog posts.
Suppose sensitive words Blog park, blog.
After processing
Bo _ guest _ garden has a lot of good bo _ Wen.
Regular expressions provide a convenient way for us.
Regex.Replace (Input, Rules,new matchevaluator (delegate (Match m) { if (string. IsNullOrEmpty (m.value) | | M.value.tochararray (). Length = = 0) return string. Empty; return string. Join ("_", M.value.tochararray ());}));
The first parameter is the retrieved article.
The second parameter is a matching rule that supports multiple lookups, with the intermediate use of |. such as Blog Park | articles.
The third is a custom method that handles matching to the data.
In the example above, rules: Blog Park | articles
Delegate will execute two times. The first match to the blog Park, the second is the article.
Replace multiple sets of text with regular expressions