Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想匹配一个字符串只包含两个单词,比如user:passwd格式,我的建议是
user:passwd
Regex.match?(%r/^\w:\w$/, string)
但它不起作用....有人可以帮助我吗?
我希望这些示例匹配a:b aa:23bw:
a:b
aa:23bw
和这些例子不匹配:a: b,a:b c
a: b
a:b c
你+在你\w的 s 之后缺少一个。我不熟悉 Elixer,但也许
+
\w
Regex.match?(%r/^[a-zA-Z0-9]+:[a-zA-Z0-9]+$/, string)
这是基本的正则表达式。