variable $LAST_MATCH_INFO

$LAST_MATCH_INFO -> MatchData | nil[permalink][rdoc][edit] [added by English]

$~ の別名

require "English"

str = "<a href=https://www.ruby-lang.org/en/about/license.txt>license</a>"

if /<a href=(.+?)>/ =~ str
  p $LAST_MATCH_INFO[0] #=> "<a href=https://www.ruby-lang.org/en/about/license.txt>"
  p $LAST_MATCH_INFO[1] #=> "https://www.ruby-lang.org/en/about/license.txt"
  p $LAST_MATCH_INFO[2] #=> nil
end