Skip to content
Advertisement

Regex not working on email domain selection properly

JavaScript

Can anyone tell me what is the mistake, my .com example is not working properly

Advertisement

Answer

You need

  • A grouping construct instead of character classes
  • A regex literal notation so that you do not have to double escape special chars
  • The ^ anchor at the start of the pattern since you need both ^ and $ to make the pattern match the entire string.

So you need to use

JavaScript

See the regex demo.

If you need to make it case insensitive, add i flag,

JavaScript
Advertisement