Skip to main content
brian_li
New Member
Jul 30, 2020 9:01 AM UTC
Question

Regex negative lookahead not working

Hi All,

 

I am trying to use regex to catch some specific email address while excluding some and seems regex negative lookahead is not working in FortiMail. Can anyone confirm that or me just doing it wrong?

 

My regex is to search in header with line "start with from:" and end with "example.com", but ignore anything from @support.example.com

(?!^from:.*@support\.example\.com$)(^from:.*example\.com$)

 

Thanks a lot.

Brian

    1 reply

    rwpatterson
    New Member
    Jul 30, 2020 1:00 PM UTC

    brian.li wrote:

    Hi All,

     

    I am trying to use regex to catch some specific email address while excluding some and seems regex negative lookahead is not working in FortiMail. Can anyone confirm that or me just doing it wrong?

     

    My regex is to search in header with line "start with from:" and end with "example.com", but ignore anything from @support.example.com

    (?!^from:.*@support\.example\.com$)(^from:.*example\.com$)

     

    Thanks a lot.

    Brian

    Try /^from:.*example\.com$/

    Starts with "from:", ignores an unlimited amount in the middle, ends with "example.com". I escaped the dot in .com so it won't match any character in that space.

     

    ** Added: I just saw the second half where you already did that. Sorry not able to add more information. Not sure if Fortimail uses standard regex, but try square brackets instead? And use the pipe between. i.e.

    [?!^from:.*@support\.example\.com$|^from:.*example\.com$]

    This would equate to not matching on the first half or matching the second half.

     

    Hope that helps.

    Translate
    Risk and Resilience in the Age of AI. An OT Thought Leadership Summit for Houston's Critical Infrastructure Leaders. Date: Thursday, December 3, 2026. Time: 8:30 am - 1:30 pm (CT). Location: The Westin Houston, Memorial City | 945 Gessner Road, Houston, TX 77024