-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[[ ' aaaa' =~ a* ]] && echo ${BASH_REMATCH[0]} || echo no #137
Comments
I think it does match the empty sequence at first.
[[ ' aaaa' =~ aa* ]] && echo ${BASH_REMATCH[0]} || echo no
[[ ' aaaa' =~ a+ ]] && echo ${BASH_REMATCH[0]} || echo no The last example in your picture is not reproducible. |
Try:
|
PS: the echo no never takes place. Works like this:
|
It has no difference with this: [[ ' aaaa' =~ (a+) ]] && echo ${BASH_REMATCH[0]} || echo no aaaa |
but you must use the extra curly braces to get the no when the regex is not found
|
Second expression does not match irrespective to the braces. |
excuse me, output is empty |
Output is empty because This is legit match or not greedy match. Lazy match example: [[ ' aaaa ' =~ .*a* ]] && { echo ${BASH_REMATCH[0]} ;} || echo no aaaa In greedy regex expressions mode the |
the output is empty, I think it be aaaa ?
would you please tell me why this happened?
I made some effort to resolve ths, but failed...
The text was updated successfully, but these errors were encountered: