1

I need help to create a regex that filters the strings have at least one number, uppercase letter, one lowercase letter and ends with "@xyz.sd" I've tried that so far,

(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z0-9@\.]{12,25}

This full fill all the conditions except the "@xyz.sd" part. I tried to do that by,

(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z0-9@\.]+(@xyz.sd){12,25}

But it does not work.

tontus
  • 179
  • 2
  • 17
  • Possible duplicate of [Regular Expression for password validation](https://stackoverflow.com/questions/5859632/regular-expression-for-password-validation) – Poul Bak Nov 28 '18 at 18:32

1 Answers1

3

You may use another lookahead and you need to use anchors:

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*@xyz\.sd$)[a-zA-Z0-9@.]{12,25}$

Or better you can use this regex:

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z0-9@.]{5,18}@xyz\.sd$

Used quantifier range {5,18} instead of {12,25} as 7 characters will be consumed by @xyz.sd.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    First one also works but you need to select multiline flag. Though I would recommend using 2nd one. – anubhava Nov 28 '18 at 18:36