ruby 正则 的陷阱
众所周知,正则表达式中 ^匹配字符串的 开始, $ 匹配字符串的 结束。
而ruby 正则中的, ^ 匹配的是行开始, $匹配的是行结尾, 字符串的开始和 结束 应该 用 \A \z.
下面看个例子吧:
str = "string\n&@*" str.match(/^\w+$/) #=> #<MatchData "string">
str.match(/\A\w+$\z/) #=> nil
posted on 2011-12-08 11:23 Eric812048774 阅读(241) 评论(0) 收藏 举报
浙公网安备 33010602011771号