るりまサーチ

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

別のキーワード

  1. kernel $~
  2. _builtin $~
  3. $~ kernel
  4. $~ _builtin
  5. $~ matchdata

クラス

モジュール

キーワード

検索結果

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

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

...atchDataオブジェクトです。
Regexp.last_match の別名です。

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

この値に代入すると Regexp.last_match や、 $&, $1, $2, ... などの関連する組み込み変数の値が変化...
...ます。

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

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

String#byterindex(pattern, offset = self.bytesize) -> Integer | nil (20.0)

文字列のバイト単位のインデックス offset から左に向かって pattern を探索します。 最初に見つかった部分文字列の左端のバイト単位のインデックスを返します。 見つからなければ nil を返します。

...ex(/o+/) # => 2
$~
#=> #<MatchData "o">

# 最長にするには否定戻り読み(negative look-behind)と組み合わせる
'foo'.byterindex(/(?<!o)o+/) # => 1
$~
#=> #<MatchData "oo">

# またはbyteindexを否定先読み(negative look-ahead)
'foo'.byteindex(/o+(?!.*o)/) # => 1
$~
#=> #<MatchDa...

MatchData#to_s -> String (8.0)

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

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

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

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

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

...した場合発生します。

//emlist[例][ruby]{
str = "This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
p $~ # => "This is Regexp"

t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp # ここも使用されない
', Regexp::...

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

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

...した場合発生します。

//emlist[例][ruby]{
str = "This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
p $~ # => "This is Regexp"

t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp # ここも使用されない
', Regexp::...

絞り込み条件を変える