Frage

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

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top