Ruby定义一个正则表达式
示例
可以在Ruby中以三种不同的方式创建Regexp。
使用斜杠://
使用%r{}
使用Regex.new
#以下形式是等效的
regexp_slash=/hello/
regexp_bracket=%r{hello}
regexp_new=Regexp.new('hello')
string_to_match="你好,世界!"
#所有这些将返回真实值
string_to_match=~regexp_slash #=>0
string_to_match=~regexp_bracket #=>0
string_to_match=~regexp_new #=>0
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短