Guest User

Untitled

a guest
Aug 6th, 2018
817
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:[email protected]'>[email protected]</a> abc [email protected]";
  7.  
  8. "ttt <a href='mailto:[email protected]'>[email protected]</a> abc <a href='mailto:[email protected]'>[email protected]</a>";
  9.  
  10.  
  11.  
  12. public void Test()
  13. {
  14.  
  15. 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})?)");
  16. MatchCollection matchCollection = pattern.Matches("ttt <a href='mailto:[email protected]'>[email protected]</a> abc [email protected]");
  17. foreach (Match match in matchCollection)
  18. {
  19. Debug.WriteLine(match);
  20. }
  21. }
  22.  
  23. Regex pattern = new Regex(@"(?<!mailto:)b[w-]+@[a-z0-9-]+(.[a-z0-9-])*.[a-z]{2,8}b(?!</a)");
  24. MatchCollection matchCollection = pattern.Matches("ttt <a href='mailto:[email protected]'>[email protected]</a> abc [email protected]");
  25. foreach (Match match in matchCollection)
  26. {
  27. Debug.WriteLine(match);
  28. }
Add Comment
Please, Sign In to add comment