以下の内容はhttps://tbpgr.hatenablog.com/entry/20141122/1416669176より取得しました。


Ruby | Regexp | ~

概要

Regexp#-

詳細

以下と同じ

self =~ $_
サンプルコード
require 'tbpgr_utils'

$_ = "hogehigehage"

~ /(h.ge)(h.ge)(h.ge)/
bulk_puts_eval binding, <<-EOS
Regexp.last_match
Regexp.last_match(0)
Regexp.last_match(1)
Regexp.last_match(2)
Regexp.last_match(3)
Regexp.last_match(4)
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

Regexp.last_match    # =>                #<MatchData "hogehigehage" 1:"hoge" 2:"hige" 3:"hage">
Regexp.last_match(0) # => "hogehigehage"
Regexp.last_match(1) # => "hoge"
Regexp.last_match(2) # => "hige"
Regexp.last_match(3) # => "hage"
Regexp.last_match(4) # => nil



以上の内容はhttps://tbpgr.hatenablog.com/entry/20141122/1416669176より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14