RegEx to make sure that the string contains at least one lower case char, upper case char, digit and symbol

RegEx to make sure that the string contains at least one lower case char, upper case char, digit and symbol

Asked on December 28, 2018 in Regex.
Add Comment


  • 2 Answer(s)

    RegEx to make sure that the string contains at least one lower case char, upper case char, digit and symbol:

    For one single regex use this:

    (?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W)
    

    In briefly:

    (?=.*[a-z])   // use positive look ahead to see if at least one lower case letter exists
    (?=.*[A-Z])  // use positive look ahead to see if at least one upper case letter exists
    (?=.*\d)    // use positive look ahead to see if at least one digit exists
    (?=.*\W])   // use positive look ahead to see if at least one non-word character exists
    

    In SilentGhost, \W replace it with a character set like this way: [[email protected]#$%^&*.,?].

    Answered on December 28, 2018.
    Add Comment

    To make sure that the string contains at least one lower case char, upper case char, digit and symbol in regex:

    • Match those three groups separately, and make sure that they all present.
    • And, [^\w]  can replace it with \W.
    Answered on December 28, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.