Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7812715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:36:11+00:00 2026-06-02T04:36:11+00:00

I have the following regex that checks for a password policy. it is validated

  • 0

I have the following regex that checks for a password policy. it is validated to work:

(^([zZ]\d{3})*$)|((?=.{9,})(?=.*?[^\w\s])(?=.*?[0-9])(?=.*?[A-Z]).*?[a-z].*)

I want to use the regex in a bash script to validate a psssword the following way :

echo $password | grep "(^([zZ]\d{3})*$)|((?=.{9,})(?=.*?[^\w\s])(?=.*?[0-9])(?=.*?[A-Z]).*?[a-z].*)"
if [[ $? -eq 0 ]] ; then

This does not work in bash.
My question is :

How do i convert this “pure” regex to a one that work in bash ? which characters do i need to escape, what is the correct way to pass the regex to grep ? are there any other things i need to look out for ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:36:12+00:00Added an answer on June 2, 2026 at 4:36 am

    This may be difficult.

    Standard grep has limited capabilities. It only supports POSIX extended regular expressions which do not recognize the lookahead assertions your regex relies on.

    If you have GNU grep on your machine, you can pass it the -P or --perl-regexp parameter, allowing it to use Perl compatible regular expressions. Then your regex should work.

    As mentioned in my comment, the regex as-is is not suitable for passwort validation. It allows passwords like z000 or even the empty string:

    (                 # Either match and capture...
     ^                #  Start of the string
     (                #  Match (and capture, uselessly in this case)
      [zZ]            #  case-insensitive z
      \d{3}           #  three digits
     )*               #  zero(!) or more times
     $                #  until the end of the string
    )                 # End of first group.
    |                 # OR
    (                 # match and capture...
      (?=.{9,})       #  a string that's at least 9 characters long,
      (?=.*?[^\w\s])  #  contains at least one non-alnum, non-space character,
      (?=.*?[0-9])    #  at least one ASCII digit
      (?=.*?[A-Z])    #  at least one ASCII uppercase letter
      .*?[a-z].*      #  and at least one ASCII lowercase letter
    )                 # no anchor to start/end of string...
    

    Better use

    ^(?=.{9})(?=.*?[^\w\s])(?=.*?[0-9])(?=.*?[A-Z]).*?[a-z].*$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following regex that isn't working. I want to match the string
I have the following REGEX that checks for a pattern like (alpha and decimals
I have been trying to write a regex that will remove whitespace following a
I have the following regex: ^[a-zA-Z](.*)[a-zA-Z]$ on both the Javascript and PHP side that
I am using the following regex in .NET to validate that a string contains
Is it possible to use a RegEx to validate, or sanitize Base64 data? That's
I have the following regex that requires 1 number, 1 letter upper and 1
I have following regex (abc|def)( ?(\\d+|(?:(?!\\1)[a-z])+)?)* with matches perfectly the subject abc123 456 .
I have the following regex date validator but it is allowing the following date:
I have the following regex which validates dates: //are not both dates if (!methods._isDate(first[0].value)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.