Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Regex for detecting emails in text
- string sRegex = @"([w-]+(.[w-]+)*@([a-z0-9-]+(.[a-z0-9-]+)*?.[a-z]{2,6}|(d{1,3}.){3}d{1,3})(:d{4})?)";
- Regex Regx = new Regex(sRegex, RegexOptions.IgnoreCase);
- string sContent = "ttt <a href='mailto:someone@example.com'>someemail@mail.com</a> abc email@email.com";
- "ttt <a href='mailto:someone@example.com'>someemail@mail.com</a> abc <a href='mailto:email@email.com'>email@email.com</a>";
- someemail@mail.com
- email@email.com
- public void Test()
- {
- 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})?)");
- MatchCollection matchCollection = pattern.Matches("ttt <a href='mailto:someone@example.com'>someemail@mail.com</a> abc email@email.com");
- foreach (Match match in matchCollection)
- {
- Debug.WriteLine(match);
- }
- }
- Regex pattern = new Regex(@"(?<!mailto:)b[w-]+@[a-z0-9-]+(.[a-z0-9-])*.[a-z]{2,8}b(?!</a)");
- MatchCollection matchCollection = pattern.Matches("ttt <a href='mailto:so1meone@example.com'>someemail@mail.com</a> abc email@email.com");
- foreach (Match match in matchCollection)
- {
- Debug.WriteLine(match);
- }
Add Comment
Please, Sign In to add comment