You're missing a +
after your \w
s. I'm not familiar with Elixer, but perhaps
Regex.match?(%r/^[a-zA-Z0-9]+:[a-zA-Z0-9]+$/, string)
This is basic Regex.
Question
I want to match a string to contain only two words, like a user:passwd
format, my suggesting is
Regex.match?(%r/^\w:\w$/, string)
But it doesn't works.... Could someone helps me?
I want these examples to match: a:b
aa:23bw
;
and these examples not to match: a: b
, a:b c
Solution
You're missing a +
after your \w
s. I'm not familiar with Elixer, but perhaps
Regex.match?(%r/^[a-zA-Z0-9]+:[a-zA-Z0-9]+$/, string)
This is basic Regex.