2011年12月8日

ruby 正则 的陷阱

摘要: 众所周知,正则表达式中 ^匹配字符串的 开始, $ 匹配字符串的 结束。而ruby 正则中的,^ 匹配的是行开始, $匹配的是行结尾, 字符串的开始和 结束 应该 用\A \z.下面看个例子吧:str = "string\n&@*"str.match(/^\w+$/) #=> #<MatchData "string">str.match(/\A\w+$\z/) #=> nil 阅读全文

posted @ 2011-12-08 11:23 Eric812048774 阅读(237) 评论(0) 推荐(1) 编辑

导航