I need to check if a 4-character string is hexadecimal, I found another question that demonstrates exactly what I want to do, but this is Java: The regular expression for checking a string contains only hexadecimal characters
How can i do this?
I am reading ruby ββdocuments for regular expressions, but I don't understand how to return true or false based on this match?
In ruby ββregex, \ h corresponds to a hexadecimal digit, while \ H corresponds to a non-hexadecimal digit.
So !str[/\H/] is what you are looking for.
!str[/\H/]
if str =~ /^[0-9A-F]+$/
does the trick. If you want case insensitive then:
str =~ /^[0-9A-F]+$/i