Simplistically, e-mail like account1@example.com can be described as one or more letters and digits followed by @ followed by letters followed by dot and followed by more letters. Regular expressions has keywords to represent any letter, any digit, explicit symbol and repetition. The keywords are different in different regular expressions languages. In this tutorial I will use Perl compatible regular expressions language as most capable. In this language keyword for any letter is [[:alpha:]], letters and digits are [[:alnum:]], @ is @ and dot needs to be escaped by back slash. Repetition for one or more is +. Combining it we get [[:alnum:]]+@[[:alpha:]]+\.[[:alpha:]]+ simplistic regular expression to search for e-mails in text.
To replace @ with at in e-mail we need to take part of e-mail before @, append at and append part of e-mail after @. In search regular expression we must tag parts of e-mail before and after @ with parenthesis - ([[:alnum:]]+)@([[:alpha:]]+\.[[:alpha:]]+). Tagged expressions are automatically numbered from left to right starting with 1 and we can use them in formatting regular expression preceding numbers with $ - $1 at $2.Having the same a++; a--; a + 1; a - 1; positive lookbehind (?<=a)[+-] and negative lookbehind (?<![ +-])[+-] will match only first two + and - symbols.
Copyright 2008 - 2025 Vlasov Studio (Best in class Visual Studio extensions and tools)