I'm trying to validate email addresses using a regex pattern with negative lookbehind. More specifically, allow only those that don't end on a specific sequence @mydomain.de.
This works fine on most of my test strings. However, adding a newline at the end of the string (\r\n) seems to break it, as it does no longer match.
I'm aware that this could normally be more easily solved using .endsWith(). I'm just intending to use the regex in a javax pattern annotation.
Pattern p = Pattern.compile("^.*(?<!@mydomain\\.de)$")
p.matcher("test@gmail.com").matches() // => true
p.matcher("test@gmail.com\r\n").matches() // => false
I would expect both strings to match as they do not end on the forbidden sequence @mydomain.de