るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Kernel$$~ -> MatchData | nil (18101.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"
//}...

ruby 1.6 feature (66.0)

ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。

...1
1.1
:
1.9

: 2002-04-01: ((<組み込み変数/$~>))

$~
に nil を代入できないバグが修正されました。((<ruby-dev:16697>))

/foo/ =~ "foo"
p $~
$~
= nil
p $~
=> ruby 1.6.7 (2002-03-01) [i586-linux]
#<MatchData:0x401b1be4>...
..."評価"

: 2002-03-16 $~

正規表現マッチのメソッドが実際には内部でマッチを実行しない場合に
$~
の状態をクリアしていませんでした。
((<ruby-bugs-ja:PR#208>))

/foo/ =~ "foo"
/foo/ =~ nil
p $~

/foo/ =~ "foo"...
...$_ = nil; ~"foo"
p $~

/foo/ =~ "foo"
"foo".index(/bar/, 4)
p $~

/foo/ =~ "foo"
"foo".rindex(/bar/, -4)
p $~

=> ruby 1.6.7 (2002-03-06) [i586-linux]
#<MatchData:0x401b1be4>
#<MatchData:0x401b198c>...

static void special_local_set(char c, VALUE val) (32.0)

$~ と $_ をセットします。 現在は c=0 が $_ で c=1 が $~ です。

...
$~
と $_ をセットします。
現在は c=0 が $_ で c=1 が $~ です。...

String#byterindex(pattern, offset = self.bytesize) -> Integer | nil (18.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...

VALUE rb_backref_get(void) (16.0)

現在の SCOPE の $~ の値を返します。

...現在の SCOPE の $~ の値を返します。...

絞り込み条件を変える

void rb_backref_set(VALUE val) (16.0)

現在の SCOPE の $~ に val を代入します。

...現在の SCOPE の $~ に val を代入します。...

MatchData#to_s -> String (6.0)

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

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

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

Regexp.compile(string, option = nil, code = nil) -> Regexp (6.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 (6.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::...

StringScanner (6.0)

StringScanner は文字列スキャナクラスです。 簡単に高速なスキャナを記述できます。

...ng=euc-jp:
require 'strscan'
s = StringScanner.new("るびい") # 文字コードはEUC-JPとします
p s.exist?(/び/) #=> 4
//}

StringScanner は $~ $& $1 $2 …… などの正規表現関連変数を
セットしません。代わりに StringScanner#[] , StringScanner#matched? などの
...

絞り込み条件を変える

<< 1 2 > >>