Link to home
Start Free TrialLog in
Avatar of farzanj
farzanjFlag for Canada

asked on

Bash Regular expression

The result of the following match is successful. Why?
 x=12345 ; [[ $x =~ ^[0-9]{3} ]] && echo 3 digits

I thought I wanted only 3 digits.  So to me it should have failed.  I was only expecting it to work for x=123.

Please explain.  Also if I want to match only 3 digits, what would be the regular expression?
Avatar of kf4zmt
kf4zmt

Are you saying it echoed "12345"?  It echoed 5 digits?
ASKER CERTIFIED SOLUTION
Avatar of DalHorinek
DalHorinek
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of farzanj

ASKER

Thanks for your help.  Appreciated
Avatar of farzanj

ASKER

I think due change of interface, I had awarded points but it did not go through.  Please open it again so that I can award points.  Thanks.