æ£è¦è¡¨ç¾ãæååã®å é ã»æ«å°¾ã«ãããããã調ã¹ã
Javaã®æ£è¦è¡¨ç¾ã§ã¯Rubyã¨åããæååå
é ãã\Aããæååæ«å°¾ãã\zã
(å°æåã®zã§ãããã¨ã«æ³¨æ)ã§è¡¨ç¾ã§ãã¾ãã
ããã確èªããã¤ããã確èªã§ããªãã£ããããã
ã½ã¼ã¹ã¨çµæ
æååå é ããaã
(~/\Aa/).matcher("aiueo").find() ===> true
æååå é ããoã
(~/\Ao/).matcher("aiueo").find() ===> false
æååå é ãããã
(~/\Aã/).matcher("ããããã").find() ===> true
æååæ«å°¾ããoã
(~/o\z/).matcher("aiueo").find() ===> true
æååæ«å°¾ããaã
(~/a\z/).matcher("aiueo").find() ===> false
æååæ«å°¾ãããã
(~/ã\z/).matcher("ããããã").find() ===> false
ã^ãã\Aãã$ãã\zãã\Zãã®éã
è¡é ã^ã
m1 = (~/^d./).matcher("abc\ndefg\nhi\n") m1.find() m1[0] ===> java.util.regex.Matcher[pattern=^d. region=0,12 lastmatch=] ===> false ERROR java.lang.IndexOutOfBoundsException: index is out of range 0..-1 (index = 0) at groovysh_evaluate.run (groovysh_evaluate:2) ...
"abc\ndefg\nhi\n".find(~/^d./) ===> null
æååå é ã\Aã
m2 = (~/\Ad./).matcher("abc\ndefg\nhi\n") m2.find() m2[0] ===> java.util.regex.Matcher[pattern=\Ad. region=0,12 lastmatch=] ===> false ERROR java.lang.IndexOutOfBoundsException: index is out of range 0..-1 (index = 0) at groovysh_evaluate.run (groovysh_evaluate:2) ...
"abc\ndefg\nhi\n".find(~/\Ad./) ===> null
è¡æ«ã$ã
m3 = (~/..$/).matcher("abc\ndefg\nhi\n") m3.find() m3[0] ===> java.util.regex.Matcher[pattern=..$ region=0,12 lastmatch=] ===> true ===> hi
"abc\ndefg\nhi\n".find(~/..$/) ===> hi
æååæ«å°¾ã\zã
m4 = (~/..\z/).matcher("abc\ndefg\nhi\n") m4.find() m4[0] ===> java.util.regex.Matcher[pattern=..\z region=0,12 lastmatch=] ===> false groovy:000> m4[0] ERROR java.lang.IndexOutOfBoundsException: index is out of range 0..-1 (index = 0) at groovysh_evaluate.run (groovysh_evaluate:2) ...
"abc\ndefg\nhi\n".find(~/..\z/) ===> null
æååä¸ã®æå¾ã®è¡æ«ã\Zã
m5 = (~/..\Z/).matcher("abc\ndefg\nhi\n") m5.find() m5[0] ===> java.util.regex.Matcher[pattern=..\Z region=0,12 lastmatch=] ===> true ===> hi
"abc\ndefg\nhi\n".find(~/..\Z/) ===> hi
ãããããªãããäºæ³ã¨éããªã
çµæã¯ä»¥ä¸ã®ããã«ãªãã¨æã£ããã ãã©ã
ã^d.ã㯠de
ã\Ad.ã㯠null
ã..$ã㯠bc
ã..\zã㯠hi
ã..\Zãã¯i\n
ãã¼ããããããããã(>o<")
誰ãæãã¦ã
JavaDocã«ã¯ä»¥ä¸ã®ããã«æ¸ãã¦ãããªã
^ è¡ã®å é $ è¡ã®æ«å°¾ \A å ¥åã®å é \Z æå¾ã®è¡æ«è¨å·ãããå ´åã¯ããããé¤ãå ¥åã®æ«å°¾ \z å ¥åã®æ«å°¾
å ¥åã£ã¦ãªãã ãããã
çåç¹
groovyã¨rubyã®éãã¯ãªããï¼
ã¡ã½ãããåçã§ã¯ãªãã®ãï¼
groovy:000> "abc\ndefg\nhi\n".find(~/^d./) ===> null
irb(main):001:0> p "abc\ndefg\nhi\n".slice(/^d./) "de" => nil
å®è¡ç°å¢
- OS:Windows XP
- Groovy Version: 1.6.5
- JVM: 1.6.0_12