1

this regex is making me crazy. i thought it would work. but it does not match anything in link here

regex is:

^[a-zA-Z](?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[$\-_. +!*'()])[a-zA-Z0-9$\-_. +!*'()]*$

requirement is:

starts with a-zA-Z must have: one lowercase, one uppercase, one from given spcl chars ONLY (anything else is invalid), and finally between 10 and 40 chars long.

rajeev
  • 1,275
  • 7
  • 27
  • 45
  • Perhaps this can help: http://stackoverflow.com/questions/19605150/regex-for-password-must-be-contain-at-least-8-characters-least-1-number-and-bot – mplungjan Apr 16 '16 at 06:09
  • 1
    there were trailing `\n` in your regex..removed it and it works:-https://regex101.com/r/vU8eV7/10 – rock321987 Apr 16 '16 at 06:11
  • hi, how to use the same constraints/regex in perl to verify? I used the same regex string, but it fails. – rajeev Jun 11 '16 at 22:24

2 Answers2

1

You can use this regex with MULTILINE m flag:

/^[a-zA-Z](?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[-$_. +!*'()])[\w$. +!*'()-]{9,39}$/mg

Updated Demo

Using {9,39} instead of {10,40} because you have already matched one character [a-zA-Z] at start.

anubhava
  • 761,203
  • 64
  • 569
  • 643
0

This might help you out ^.(?=.{10,40})(?=.\d)(?=.[a-zA-Z]).$

Atula
  • 2,177
  • 2
  • 12
  • 28