Regex to replace email addresses -


i wish replace email addresses in string else. not work me.

    string body = "this 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 helpful please.

you want this:

return regex.replace(body, pattern, "hidden email address"); 

if @ documentation regex.replace, you'll see returns newly replaced string. not affect string passed in.

note: assuming you're using c#. i'm guessing are, syntax.

furthermore: if regex still isn't working well, try 1 regular expressions cookbook (by goyvaerts & levithan):

@"^[\w!#$%&'*+/=?`{|}~^.-]+@[a-z0-9.-]+$" 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -