I want to match a string that includes the characters 0-9.-,[], something like this:
return true if str =~ /\A[0-9.-,\[\]]*\Z/
Which works except it doesn't seem to match the braces, how do I match those?
I want to match a string that includes the characters 0-9.-,[], something like this:
return true if str =~ /\A[0-9.-,\[\]]*\Z/
Which works except it doesn't seem to match the braces, how do I match those?
You need to escape the .
and -
characters:
str =~ /\A[0-9\.\-,\[\]]*\Z/
turns out it also works w/o escaping the . and - characters like this:
str =~ /\A[\[\]0-9.,-]*\Z/