I have a script where i need to check the format of a string.
finally, i'm waiting a "process name" and 2 numbers separated by a ","
string like : "this_is_a_string.txt,1,10 should be ok"
string ok : "apache.exe,1,10"
string ok : "mysqld,50,0"
string not ok : "ap ache,1,10"
string not ok : "ap,ache,1,10"
string not ok : " apache,1,10"
PS : "" characters are only here to be able to show a string beginning with a space...
Here is what i tryed :
if [[ $\(expr "$PROCESS_STRING" : '^[a-z0-9\\-\\.\\_]\*,[0-9]\*,[0-9]*$'\) -ne 0 ]];
then
echo " : String OK"
else
echo " : String KO"
fi
But i always get an error :
expr: WARNING: BRE not portable: � ^[a-z0-9\-\.\_]*,[0-9]*,[0-9]*$ �: use of � ^ � character as first character of a base regular expression isn't portable; canceled.
: Format OK
The problem seems to be the "^" character at the beginning of my regex, but if i remove it, a string like " apache,1,10" would be ok but it shouldn't in my case...