Guest User

Untitled

a guest
Aug 6th, 2018
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. Regex for detecting emails in text
  2. string sRegex = @"([w-]+(.[w-]+)*@([a-z0-9-]+(.[a-z0-9-]+)*?.[a-z]{2,6}|(d{1,3}.){3}d{1,3})(:d{4})?)";
  3.  
  4. Regex Regx = new Regex(sRegex, RegexOptions.IgnoreCase);
  5.  
  6. string sContent = "ttt <a href='mailto:someone@example.com'>someemail@mail.com</a> abc email@email.com";
  7.  
  8. "ttt <a href='mailto:someone@example.com'>someemail@mail.com</a> abc <a href='mailto:email@email.com'>email@email.com</a>";
  9.  
  10. someemail@mail.com
  11. email@email.com
  12.  
  13.  
  14. public void Test()
  15. {
  16.  
  17. Regex pattern = new Regex(@"b(?<!mailto:)([w-]+(.[w-])*@([a-z0-9-]+(.[a-z0-9-]+)?.[a-z]{2,6}|(d{1,3}.){3}d{1,3})(:d{4})?)");
  18. MatchCollection matchCollection = pattern.Matches("ttt <a href='mailto:someone@example.com'>someemail@mail.com</a> abc email@email.com");
  19. foreach (Match match in matchCollection)
  20. {
  21. Debug.WriteLine(match);
  22. }
  23. }
  24.  
  25. Regex pattern = new Regex(@"(?<!mailto:)b[w-]+@[a-z0-9-]+(.[a-z0-9-])*.[a-z]{2,8}b(?!</a)");
  26. MatchCollection matchCollection = pattern.Matches("ttt <a href='mailto:so1meone@example.com'>someemail@mail.com</a> abc email@email.com");
  27. foreach (Match match in matchCollection)
  28. {
  29. Debug.WriteLine(match);
  30. }
Add Comment
Please, Sign In to add comment