Tuesday, 3 October 2023

Regex to test if gmail, javascript implementation

 https://stackoverflow.com/questions/16200965/regular-expression-validate-gmail-addresses


/
^[\w.+\-]+@gmail\.com$
/
gm
^ asserts position at start of a line
Match a single character present in the list below
[\w.+\-]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\w matches any word character (equivalent to [a-zA-Z0-9_])
.+
matches a single character in the list .+ (case sensitive)
\- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
@gmail
matches the characters @gmail literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
com
matches the characters com literally (case sensitive)
$ asserts position at the end of a line
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)


https://regex101.com/codegen?language=javascript

const regex = /^[\w.+\-]+@gmail\.com$/gm;
regex.test('saddasd');

No comments:

Post a Comment