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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -