1

Problem: To find valid e-mail.

A valid e-mail has a prefix name and a domain where:

The prefix name is a string that may contain letters (upper or lower case), digits, underscore '_', period '.', and/or dash '-'. The prefix name must start with a letter. The domain is '@leetcode.com'.

when I'm using following expression it's working fine '^[a-zA-Z][a-zA-Z0-9\.\_\-]*@leetcode[\.]com$ but

the second expression is not matching to strings with '_'(underscores) '^[a-zA-Z][a-zA-Z0-9\.\-\_]*@leetcode[\.]com$'

testcase: '[email protected]

using mysql

as per my understanding both of the regex should give same output but the first one is matching with testcase containing underscores and second one is not

1
  • Please provide enough code so others can better understand or reproduce the problem.
    – Community Bot
    Commented Feb 22 at 15:09

1 Answer 1

0

You didn't phrase the first requirement correctly:

The prefix name must start with a letter.

You used ^[a-z][A-Z] to represent the first letter, but this actually says to match a lowercase letter followed by an uppercase letter. You should have used [a-zA-Z]. Try this version:

^[a-zA-Z][a-zA-Z0-9._-]*@leetcode\.com$

Note that I place - last in the character class, as [.-_] actually matches the range of characters between . and _.

1
  • thanks @tim for pointing out the mistake and the explanation . I've updated the queries as per first requirement
    – Gorang
    Commented Feb 22 at 12:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.