Bash regex =~ operator match prefix -
why match
[[ 'hithere' =~ hi* ]] but not
[[ 'hithere' =~ *there ]]
=~ regular expressions operator. if want match 0 or more characters, you'll need .* instead of *.
[[ 'hithere' =~ hi.* ]] && echo "yes" yes [[ 'hithere' =~ .*there ]] && echo "yes" yes without anchors, though, match succeed without wildcards.
[[ 'hithere' =~ hi ]] [[ 'hithere' =~ there ]] # add anchors guarantee you're matching whole phrase. [[ 'hithere' =~ ^hi.*$ ]] [[ 'hithere' =~ ^.*there$ ]] for pattern matching, can use = unquoted value. uses bash pattern matching instead, (evidently) expecting.
[[ 'hithere' = hi* ]] && echo "yes" yes [[ 'hithere' = *there ]] && echo "yes" yes
Comments
Post a Comment