るりまサーチ

最速Rubyリファレンスマニュアル検索!
33件ヒット [1-33件を表示] (0.044秒)
トップページ > クエリ:nil[x] > クエリ:end[x] > クエリ:$~[x]

別のキーワード

  1. _builtin nil?
  2. nilclass nil?
  3. object nil?
  4. _builtin nil
  5. object nil

種類

ライブラリ

モジュール

キーワード

検索結果

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

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

...目のマッチ ($n) を取り出すためには $~[n] を使います。

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

この変数はローカルスコープかつスレッドローカルです。
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 (630.0)

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

... nil
を返すようになりました。(String#[]やString#slice と同じ結果を返すと
いうことです)

p "foo".slice!("bar") # <- 以前からこちらは nil を返していた
p "foo".slice!(5,10)

=> ruby 1.6.7 (2002-03-01) [i586-linux]
nil
...
...ーになっていました。
((<ruby-dev:17155>))

open("|-","r+") {|f|
if f
f.dup.close_write
else
sleep 1
end

}

=> ruby 1.6.7 (2002-03-01) [i586-linux]
-:3:in `close_write': closing non-duplex IO for writing (IOError)
from -:3...
...((<組み込み変数/$~>))

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

/foo/ =~ "foo"
p $~
$~
= nil
p $~
=> ruby 1.6.7 (2002-03-01) [i586-linux]
#<MatchData:0x401b1be4>
-:3: wrong argument type nil (expected Match) (Typ...

StringScanner (60.0)

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

...ngScanner.new('This is an example string')
s.eos? #=> false

p s.scan(/\w+/) #=> "This"
p s.scan(/\w+/) #=> nil
p s.scan(/\s+/) #=> " "
p s.scan(/\s+/) #=> nil
p s.scan(/\w+/) #=> "is"
s.eos? #=> false

p s.scan(/\s+/) #=> " "
p s.scan(/\w+/) #=> "an"
p s.scan(/\s...
...string/) #=> nil
p s.scan(/\s+/) #=> " "
p s.scan(/string/) #=> "string"
end


def case2
s = StringScanner.new('test string')
p s.scan_until(/t/) #=> "t"
p s.scan_until(/\w+/) #=> "est"
p s.scan_until(/string/) #=> " string"
p s.scan_until(/\s+/) #=> nil
p s.scan_...
...ng=euc-jp:
require 'strscan'
s = StringScanner.new("るびい") # 文字コードはEUC-JPとします
p s.exist?(/び/) #=> 4
//}

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