るりまサーチ

最速Rubyリファレンスマニュアル検索!
44件ヒット [1-44件を表示] (0.075秒)

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

クラス

モジュール

キーワード

検索結果

Kernel$$~ -> MatchData | nil (26225.0)

現在のスコープで最後に成功したマッチに関する MatchDataオブジェクトです。 Regexp.last_match の別名です。

...後に成功したマッチに関する MatchDataオブジェクトです。
Regexp.last_match の別名です。

このデータから n 番目のマッチ ($n) を取り出すためには $~[n] を使います。

この値に代入すると Regexp.last_match や、 $&, $1, $2, ... などの関...
...連する組み込み変数の値が変化します。
Match
Data オブジェクトでも nil でもない値を代入しようとすると TypeError が発生します。

この変数はローカルスコープかつスレッドローカルです。
Ruby起動時の初期値は nil です。

//em...
...list[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
if %r[<a href="(.*?)">(.*?)</a>] =~ str
p $~[1]
end
#=> "http://example.com"
//}...

MatchData#to_s -> String (11008.0)

マッチした文字列全体を返します。

...マッチした文字列全体を返します。

//emlist[例][ruby]{
/bar/ =~ "foobarbaz"
p $~ # => #<MatchData:0x401b1be4>
p $~.to_s # => "bar"
//}...

Regexp.compile(string, option = nil, code = nil) -> Regexp (8032.0)

文字列 string をコンパイルして正規表現オブジェクトを生成して返します。

...s is regexp", Regexp::IGNORECASE)
t1.match(str)
p $~ # => "This is Regexp"

t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp # ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
p Regexp.last_match # => "This is Regexp"

str = "ふ...
...るいけや\nかわずとびこむ\nみずのおと"
t2 = Regexp.compile("ふる.*?と", Regexp::MULTILINE)
p t2.match(str)[0] # => "ふるいけや\nかわずと"
//}...

Regexp.new(string, option = nil, code = nil) -> Regexp (8032.0)

文字列 string をコンパイルして正規表現オブジェクトを生成して返します。

...s is regexp", Regexp::IGNORECASE)
t1.match(str)
p $~ # => "This is Regexp"

t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp # ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
p Regexp.last_match # => "This is Regexp"

str = "ふ...
...るいけや\nかわずとびこむ\nみずのおと"
t2 = Regexp.compile("ふる.*?と", Regexp::MULTILINE)
p t2.match(str)[0] # => "ふるいけや\nかわずと"
//}...