.net - C# RegEx Replacement -


I'm adding an Ignition filter and what I would like to do is replace the word (or partial word) that is replaced by the same A string of length is a part of the equal length, where I'm having trouble.

So if the replacement word is 3 characters long, then I want the text to be changed to 3 characters. I'm not sure how to match the length of the word I can be replaced to my replacement string.

Here's my test method:

  public static string ProfanityFilter (string text) {string pattern = @ "\ bword \ b | \ bword2 \ b | \ banother * "; Reggae Reggae = new Reggae (Pattern); String replacement = "*% $ @ ^! # @! @ $ ^ ()!"; Return regex.Replace (text, replacement); }   

Therefore, if the word "other" has been changed, then it will be replaced with "*% $ @ ^! #"

If "word" is changed it will be replaced with "*% $ @ ^"

If "wording" has been changed, then it will be replaced with "*% $ @

Match match) {string replacement = "! *% $ @ ^ # @ $ ^ ()"; Return replacement Shuttle (0, match. Captain [0]. Lambic); }

then converted

  Regex Rivax. Replay (text, replacement);   

to

  Regex back. Replay (text, sensor);    

Try this approach:

  string Input = "foo word bar word 2 forum air"; String pattern = @ "\ b (?: Word | word 2 | second) \ b"; String result = Reggae Replay (Input, Pattern, M => New String ('*', M. Lang)); Console.WriteLine (results);   

The idea is to use overloaded which one accepts. I am providing mail evaluator via Lambda expression and reaching the Match.Length property to determine the length of the match code.

I have introduced your pattern to match exact match by inserting \ b metacharactor at the start and end of the red eye alternate matches. However, depending on your "wording" = "*% $ @ ^ ing" example, it seems that you want to support partial matches in that case you should use \ b .

Comments