298件ヒット
[1-100件を表示]
(0.162秒)
ライブラリ
- ビルトイン (298)
キーワード
- == (12)
- [] (48)
- begin (12)
- byteoffset (6)
- captures (12)
- deconstruct (2)
-
deconstruct
_ keys (2) - end (12)
- eql? (12)
- hash (12)
- inspect (12)
- length (12)
-
named
_ captures (12) - names (12)
- offset (24)
-
post
_ match (12) -
pre
_ match (12) - regexp (12)
- size (12)
- string (12)
-
to
_ a (12) -
to
_ s (12) -
values
_ at (12)
検索結果
先頭5件
-
MatchData
# post _ match -> String (9102.0) -
マッチした部分より後ろの文字列を返します($'と同じ)。
...マッチした部分より後ろの文字列を返します($'と同じ)。
//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.post_match # => "baz"
//}
@see MatchData#pre_match... -
MatchData
# pre _ match -> String (9102.0) -
マッチした部分より前の文字列を返します($`と同じ)。
...マッチした部分より前の文字列を返します($`と同じ)。
//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.pre_match # => "foo"
//}
@see MatchData#post_match... -
MatchData
# deconstruct _ keys(array _ of _ names) -> Hash (6124.0) -
引数で指定された名前の名前付きキャプチャを Hash で返します。
...list[例][ruby]{
m = /(?<hours>\d{2}):(?<minutes>\d{2}):(?<seconds>\d{2})/.match("18:37:22")
m.deconstruct_keys([:hours, :minutes]) # => {:hours => "18", :minutes => "37"}
m.deconstruct_keys(nil) # => {:hours => "18", :minutes => "37", :seconds => "22"}
# 名前付きキャプチャが定義され......ていなかった場合は空のハッシュを返す
m = /(\d{2}):(\d{2}):(\d{2})/.match("18:37:22")
m.deconstruct_keys(nil) # => {}
//}
@see d:spec/pattern_matching#matching_non_primitive_objects... -
MatchData
# captures -> [String] (6102.0) -
$1, $2, ... を格納した配列を返します。
...ます。
MatchData#to_a と異なり $& を要素に含みません。
グループにマッチした部分文字列がなければ対応する要素は nil になります。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
p $~.captures......# => ["foo", "bar", nil]
//}
@see MatchData#to_a, MatchData#named_captures......# => ["foo", "bar", nil]
//}
@see MatchData#to_a, MatchData#named_captures, d:spec/pattern_matching#matching_non_primitive_objects... -
MatchData
# deconstruct -> [String] (6102.0) -
$1, $2, ... を格納した配列を返します。
...ます。
MatchData#to_a と異なり $& を要素に含みません。
グループにマッチした部分文字列がなければ対応する要素は nil になります。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
p $~.captures......# => ["foo", "bar", nil]
//}
@see MatchData#to_a, MatchData#named_captures, d:spec/pattern_matching#matching_non_primitive_objects... -
MatchData
# inspect -> String (6102.0) -
self の内容を人間に読みやすい文字列にして返します。
...puts /.$/.match("foo").inspect
# => #<MatchData "o">
puts /(.)(.)(.)/.match("foo").inspect
# => #<MatchData "foo" 1:"f" 2:"o" 3:"o">
puts /(.)(.)?(.)/.match("fo").inspect
# => #<MatchData "fo" 1:"f" 2:nil 3:"o">
puts /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").inspect
# => #<MatchData "hog" foo:"... -
MatchData
# named _ captures -> Hash (6102.0) -
名前付きキャプチャをHashで返します。
...atch("01")
m.named_captures # => {"a" => "0", "b" => "1"}
m = /(?<a>.)(?<b>.)?/.match("0")
m.named_captures # => {"a" => "0", "b" => nil}
m = /(?<a>.)(?<a>.)/.match("01")
m.named_captures # => {"a" => "1"}
m = /(?<a>x)|(?<a>y)/.match("x")
m.named_captures # => {"a" => "x"}
//}
@see MatchData#cap......tures, MatchData#deconstruct_keys... -
MatchData
# named _ captures(symbolize _ names: false) -> Hash (6102.0) -
名前付きキャプチャをHashで返します。
...{
m = /(?<a>.)(?<b>.)/.match("01")
m.named_captures # => {"a" => "0", "b" => "1"}
m = /(?<a>.)(?<b>.)?/.match("0")
m.named_captures # => {"a" => "0", "b" => nil}
m = /(?<a>.)(?<a>.)/.match("01")
m.named_captures # => {"a" => "1"}
m = /(?<a>x)|(?<a>y)/.match("x")
m.named_captures # => {"a" => "x"}......m = /(?<a>.)(?<a>.)/.match("01")
m.named_captures(symbolize_names: true) #=> {:a => "1"}
//}
@see MatchData#captures, MatchData#deconstruct_keys... -
MatchData
# [](range) -> [String] (3018.0) -
Range オブジェクト range の範囲にある要素からなる部分配列を返します。
Range オブジェクト range の範囲にある要素からなる部分配列を返します。
@param range start..end 範囲式。
//emlist[例][ruby]{
/(foo)(bar)/ =~ "foobarbaz"
p $~[0..2] # => ["foobar", "foo", "bar"]
//} -
MatchData
# [](n) -> String | nil (3003.0) -
n 番目の部分文字列を返します。
n 番目の部分文字列を返します。
0 はマッチ全体を意味します。
n の値が負の時には末尾からのインデックスと見倣します(末尾の
要素が -1 番目)。n 番目の要素が存在しない時には nil を返します。
@param n 返す部分文字列のインデックスを指定します。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
p $~[0] # => "foobar"
p $~[1] # => "foo"
... -
MatchData
# [](name) -> String | nil (3003.0) -
name という名前付きグループにマッチした文字列を返します。
...m name 名前(シンボルか文字列)
@raise IndexError 指定した名前が正規表現内に含まれていない場合に発生します
//emlist[例][ruby]{
/\$(?<dollars>\d+)\.(?<cents>\d+)/.match("$3.67")[:cents] # => "67"
/(?<alpha>[a-zA-Z]+)|(?<num>\d+)/.match("aZq")[:num] # => nil
//}...