regex - BASH Check if variable match (or not) regexpr -
i need find out how check if variable matches defined regexp. let's have var1="abcd,1234"
, vars have match regexpr bellow. see, var not match has comma, how check? have created if statement below, did not work:
if [[ ${var1} == ^[a-za-z0-9`~!@#$%^&*()_+-={}|[]:";'?] ]]
thanks.
#!/bin/bash regex="^[^,]*[^ ,][^,]*$" var="$1" if [[ "$var" =~ $regex ]] echo "matches"; else echo "doesn't match!"; fi
that check string not have comma..
Comments
Post a Comment