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

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -