|
From: | Mike Stroyan |
Subject: | Re: How to use [[ string =~ regexp ]]? |
Date: | Sun, 21 May 2006 13:57:41 -0600 |
On 5/21/06, Peter Volkov <pvolkov@mics.msu.su> wrote:
I have problems using =~ operator. I've tried to search for answer, but failed. I'm using GNU bash, version 3.1.17. Can anybody give me some examples of usage? I really do not understand why $ [[ "string" =~ "[a-z]" ]] && echo something something echo me something. IIUC the regular expression [a-z] matches any single letter, so how string "string" matches one letter?
The =~ regexp match will match a substring by default. You can use ^ and $ to anchor the expression to the start and end of the string. You won't get a match with [[ "string" =~ "^[a-z]$" ]] && echo match But you will get a match with [[ "string" =~ "^[a-z]{6}$" ]] && echo match because it matches the correct number of characters. -- Mike Stroyan stroyan@gmail.com
[Prev in Thread] | Current Thread | [Next in Thread] |