Search code examples
c#regexemailhyperlink

Searching for the word "Unsubscribe" as a hyperlink in an email


I am trying to look through emails in a folder and determine if they contain the word 'Unsubscribe' as a hyperlink. Currently I am looking at the body of the Item and searching for the word unsubscribe by doing

if (body.Contains("Unsubscribe"))

I was wondering how to search for a hyperlink with a specified word. Thanks


Solution

  • Given that you're looking for a hyperlink with the word "Unsubscribe" in it, you can use the following regex:

    <a.*?href.*?>[\S]*?[uU]nsubscribe.*[\S]</a>

    This will search for any hyperlink with "unsubscribe" or "Unsubscribe" somewhere in it.

    Try it here!