简体   繁体   English

为什么这个ruby正则表达式不匹配这个字符串?

[英]Why won't this ruby regex match this string?

x = "output/file.zip"

x =~ /output\/.\../

returns nil. 返回零。 There is something wrong with escaping the period, but I can't figure it out. 逃避这段时间有问题,但我无法弄清楚。

. usually means "any character" in regex. 通常在正则表达式中表示“任何字符”。 Try .* , which means " . repeated zero or more times": 试试.* ,这意味着“重复零次或多次”: .

x =~ /output\/.*\..*/

Works fine for me. 对我来说很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM