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

Was it helpful?

Solution

You're missing a + after your \ws. I'm not familiar with Elixer, but perhaps

Regex.match?(%r/^[a-zA-Z0-9]+:[a-zA-Z0-9]+$/, string)

This is basic Regex.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top