Access denied, Please sign in and make sure you have proper permission.
其实也可可以/^your exgexp$/m
为啥是\A\z?WTF!好难看呀,我一直用\A\Z........
#2 楼 @hooopo 是不是因为 m flag 并不是所有情况下都能用的关系
我测试了一下似乎
"file.txt\n<script>alert('hello')</script>" =~ /^[\w\.\-\+]+$/m
是能通过的
"file.txt\n<script>alert('hello')</script>" =~ /\A[\w\.\-\+]+\z/m
则不行
m flag 好像是匹配多行,对于开头到/n 这段仍旧能匹配通过
看到这贴才注意到 rails guide 上的例子也是用这中 regx:
validates :legacy_code, :format => { :with => /\A[a-zA-Z]+\z/, :message => "Only letters allowed"}