Thursday, April 19, 2012

Convert general regex to bash proof regex

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





No comments:

Post a Comment