I wish to replace email addresses in a string to something else. It does not work for me.
string body = "this is a test abc@emailadx.com";
string pattern = @"\b[!#$%&'*+./0-9=?_`a-z{|}~^-]+@[.0-9a-z-]+\.[a-z]{2,6}\b";
Regex.Replace(body, pattern, "Hidden Email Address");
return body;
Any hints would be helpful please.
You want to do this:
If you look at the documentation for Regex.Replace, you’ll see that it returns the newly replaced string. It does not affect the string that was passed in.
NOTE: this is assuming you’re using C#. But I’m guessing you are, from the syntax.
FURTHERMORE: If your regex still isn’t working well, try this one from the Regular Expressions Cookbook (by Goyvaerts & Levithan):