I'm playing codewars in Ruby and I'm stuck on a Kata. The goal is to validate if a user input string is alphanumeric. (yes, this is quite advanced Regex)
The instructions:
At least one character ("" is not valid)
Allowed characters are uppercase / lowercase latin letters and digits from 0 to 9
No whitespaces/underscore
What I've tried :
^[a-zA-Z0-9]+$
^(?! !)[a-zA-Z0-9]+$
^((?! !)[a-zA-Z0-9]+)$
It passes all the test except one, here's the error message:
Value is not what was expected
I though the Regex I'm using would satisfy all the conditions, what am I missing ?
SOLUTION:
\A[a-zA-Z0-9]+\z
(and better Ruby :^) )
$
=> end of a line\z
=> end of a string
(same for beginning: ^
(line) and \A
(string), but wasn't needed for the test)
Favourite answer from another player:
/\A[A-z\d]+\z/