It depends on the flavor of regexp being used by the downstream application. Each language tends to have a slightly different variation, but you can try some of these "tricks".
- Use the
+
after an expression to indicate it must appear at least once.
- For example,
[^\@]+
means a non-at-sign character must appear at least once preceding the at-sign.
- You can replace
[^\@]+
with (?:\w|\.|\_|\-)+
to prevent entry of invalid names preceding "@" (for example, you cannot have a percent-sign in an email username)
- Use
(?![Aa][Bb][Cc])
instead of (?!abc)
so that the "abc" portion is not case sensitive.
- If "abc" doesn't need to be right after the "@" then add a non-capturing group representing characters which may appear before "abc" (see the fourth example below)
# lowercase "abc" which must be right after the "@"
"^[^\@]+\@(?!abc)(?:\w|\_|\-|\.)+(?:[.]\w{2,4})+$"
# case insensitive "abc" which must be right after the "@" (which may be preceded by any non-"@" characters)
"^[^\@]+\@(?![Aa][Bb][Cc])(?:\w|\_|\-|\.)+(?:[.]\w{2,4})+$"
# case insensitive "abc" which must be right after the "@" (which may be preceded by valid characters, such as alphabet letters, period, underscore)
"^(?:\w|\.|\_|\-)+\@(?![Aa][Bb][Cc])(?:\w|\_|\-|\.)*(?:[.]\w{2,4})+$"
# case insensitive "abc" which may be preceded by other valid characters
"^(?:\w|\.|\_|\-)+\@(?!(?:\w|\_|\-|\.)*[Aa][Bb][Cc])(?:\w|\_|\-|\.)*(?:[.]\w{2,4})+$"