문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top