Isuru Lakshan Isuru Lakshan - 1 month ago 13
C# Question

Identify specified text using c#

Example text : "jhon's email address is jhon@gmail.com"

I got an error when identifying jhon's email address from regex.I'm new for this regex so like to have your valuable answers .Thanks in advance
Expected result : jhon@gmail.com

Answer Source

EmailRegex shares the regex for an email address in multiple programming languages. Here are two examples:

Java:

/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i

C#:

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

To use the regex, look at the C# and Java documentation or an Java example / C# example