vbic 2007-11-15 11:02
如何用正则表达式匹配
想用regulare匹配下面一种情况
<10时匹配7
>=10时匹配个位数为3,4的数
lgn21st 2007-11-15 11:20
完全用regex来作这个?
楼主给个具体的例子吧,感觉不完全用regex可能更简单一些。
maninred 2007-11-15 11:56
正则表达式是处理字符串的吧,你这里的情况貌似处理数值的。
vbic 2007-11-15 13:22
[quote]原帖由 [i]maninred[/i] 于 2007-11-15 11:56 发表 [url=http://www.ruby-lang.org.cn/forums/redirect.php?goto=findpost&pid=7859&ptid=2045][img]http://www.ruby-lang.org.cn/forums/images/common/back.gif[/img][/url]
正则表达式是处理字符串的吧,你这里的情况貌似处理数值的。 [/quote]
学习嘛
想用regulare匹配下面一种情况
1个字符时匹配a
多个字符时匹配最后字符为b,c的 /b$|c$/
1个字符我还不清楚
xavier 2007-11-15 18:57
一个字符的话直接写
比如
[code]
a="7"
true if a=~ /7/ #=>true
[/code]
axgle 2007-11-16 10:47
[quote]原帖由 [i]vbic[/i] 于 2007-11-16 09:44 发表 [url=http://www.ruby-lang.org.cn/forums/redirect.php?goto=findpost&pid=7927&ptid=2045][img]http://www.ruby-lang.org.cn/forums/images/common/back.gif[/img][/url]
17也可以匹配 [/quote]
你要的是不是这个?
[code] /^7$/ [/code]
lgn21st 2007-11-16 13:32
[url]http://www.rubular.com/[/url]
这个网址真的很好用,我netbeans里面没有regex工具,我就用这个。
maninred 2007-11-16 16:30
[quote]原帖由 [i]lgn21st[/i] 于 2007-11-16 13:32 发表 [url=http://ruby-lang.org.cn/forums/redirect.php?goto=findpost&pid=7945&ptid=2045][img]http://ruby-lang.org.cn/forums/images/common/back.gif[/img][/url]
[url]http://www.rubular.com/[/url]
这个网址真的很好用,我netbeans里面没有regex工具,我就用这个。 [/quote]
开一个irb验证一下就ok吧。
KenXiePeng 2007-11-16 22:20
回复 #7 axgle 的帖子
/^7$/,强的
[[i] 本帖最后由 KenXiePeng 于 2007-11-16 22:33 编辑 [/i]]
bbschat 2008-1-15 22:43
笑~ 抛开类型不说,/^7$/和7几乎就是一回事。
/^7$/除了匹配一个7还能匹配什么??
antares_sco 2008-2-18 11:30
不就是要匹配7吗,又没说还得匹配别的。。。。