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 公司的祝福语简短2026
18 老爸的祝福语简短独特