You wrote:
check if there is a digit or letter before the @@
I assume you mean a digit / letter before the first @@ and check for a dot after the second @@ (as in your example).
You can use the following regex:
[a-z0-9]+ # Chars before "@@", except the last (?: # Last char before "@@" (\d) # either a digit - group 1 | # or ([a-z]) # a letter - group 2 ) @@? # 1 or 2 "at" chars ([^@]+) # "Central" part - group 3 @@? # 1 or 2 "at" chars (?: # Check for a dot (\.) # Captured - group 4 | # or nothing captured ) [a-z0-9]+ # The last part # Flags: # i - case insensitive # x - ignore blanks and comments How it works:
- Group 1 or 2 captures the last char before the first
@@(either group 1 captures a digit or group 2 captures a letter). - Group 3 catches the "central" part (THISSTRING, a sequence of chars other than
@). - Group 4 catches a dot, if any.
You can test it at https://regex101.com/r/ATjprp/1
Your regex has such an error that a dot matches any char. If you want to check for a literal dot, you must escape it with a backslash (compare with group 4 in my solution).