[Solved] Rewrite regex to accept conditional terms


Your regex doesn’t say what you think it says.

^([a-z0-9_\.-])+@[yahoo]{5}\.([com]{3}\.)?[com]{3}$

Says any characters a-z, 0-9, ., - one or more times.

That later part where you are trying match yahoo.com is incorrect. It says y, a, h, or o, any of those characters are allowed 5 times. Same with the com so aaaaa.ooo would be valid here. I’m not sure what the ([com]{3}\.)?[com]{3} was trying to say but I presume you wanted to check for .com.

See character classes documentation here, http://www.regular-expressions.info/charclass.html.

What you want is

^([a-z0-9_.\-])+@yahoo\.com$

or for more domains use grouping,

^([a-z0-9_.\-])+@(yahoo|gmail|deadforce)\.com$

You haven’t stated what language you are using so a real demo can’t be given.

Functional demo, https://jsfiddle.net/qa9x9hua/1/

1

solved Rewrite regex to accept conditional terms