Search code examples
regex-lookarounds

Guidance on Regex


I am struggling to complete this regex condition:

"Match anything that is not a legitimate subdomain of rafael.com (including the domain rafael.com)"

For example, these 3 lines should not match because they are legitimate

rafael.com
hello.rafael.com
hi.hello.rafael.com

And all the lines below should match

hello.rafael.xyz
badrafael.com
rafaelbad.com
rafaelbad.xyz
badrafael.xyz
arafael.com
arafael.xyz
rafael.xyz
a.b.rafael.xyz

This expression .*rafael(?!\.com).* gets me part of the way, but it isn't matching, for example,

badrafael.com 
arafael.com

I am getting caught up with the lookbehind portion of this regex, I have been staring at this for 3 hours and can't figure it out. Any guidance, suggestions, links to examples would be tremendously appreciated!


Solution

  • I have decided after much troubleshooting that the best way to do this is actually to create separate regexes for some of the most common scenarios that may come up when blocking domain names and their combinations, and create more than 1 rule, as opposed to trying to capture every single possible combination of a domain in 1 regex.