情報学部 | 菅沼ホーム | 目次 | 索引 |
re = Regexp.new("abc", Regexp::IGNORECASE) re =~ "xxABcyy" p Regexp.last_match[0] # "ABc" を出力
/(c..)\w+(c..)/ =~ "abcdefyycxxk" p Regexp.last_match # => #<MatchData:0x2ab064c> p Regexp.last_match[0] # => "cdefyycxx" p Regexp.last_match[1] # => "cde" p Regexp.last_match[2] # => "cxx"
re = Regexp.union(/cd/, /ab/) re =~ "xxabxxcde" p Regexp.last_match[0] # "ab" を出力 /cd|ab/ =~ "xxabxxcde" p Regexp.last_match[0] # "ab" を出力
p /ab/ =~ "xxabxxcde" # => 2 p /ab/ === "xxabxxcde" # => true
p /(c..)\w+(c..)/.match("abcdefyycxxk")[0] # => "cdefyycxx" p /(c..)\w+(c..)/.match("abcdefyycxxk")[1] # => "cde" p /(c..)\w+(c..)/.match("abcdefyycxxk")[2] # => "cxx"
情報学部 | 菅沼ホーム | 目次 | 索引 |