how to match email in regex in ruby
email_regex = /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\z/
\A
: Asserts the start of the string.[A-Za-z0-9._%+-]+
: Matches one or more occurrences of letters (both uppercase and lowercase), digits, dots, underscores, percent signs, plus signs, and hyphens.@
: Matches the at symbol.[A-Za-z0-9.-]+
: Matches one or more occurrences of letters (both uppercase and lowercase), digits, dots, and hyphens.\.
: Matches a literal dot.[A-Z|a-z]{2,}
: Matches two or more occurrences of uppercase or lowercase letters. This part is used to match the top-level domain (TLD), which should have at least two characters.\z
: Asserts the end of the string.
The entire regex pattern is designed to validate an email address by ensuring it follows a common pattern with a local part (username) followed by the at symbol and a domain part. The domain part includes a period and a TLD with at least two characters.