るりまサーチ

最速Rubyリファレンスマニュアル検索!
298件ヒット [1-100件を表示] (0.093秒)
トップページ > クエリ:t[x] > クラス:MatchData[x]

別のキーワード

  1. openssl t61string
  2. asn1 t61string
  3. matrix t
  4. t61string new
  5. fiddle type_size_t

ライブラリ

キーワード

検索結果

<< 1 2 3 > >>

MatchData#post_match -> String (9101.0)

マッチした部分より後ろの文字列を返します($'と同じ)。

...マッチした部分より後ろの文字列を返します($'と同じ)。

//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.post_match # => "baz"
//}

@see MatchData#pre_match...

MatchData#pre_match -> String (9101.0)

マッチした部分より前の文字列を返します($`と同じ)。

...マッチした部分より前の文字列を返します($`と同じ)。

//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.pre_match # => "foo"
//}

@see MatchData#post_match...

MatchData#byteoffset(n) -> [Integer, Integer] | [nil, nil] (6301.0)

n 番目の部分文字列のバイト単位のオフセットの 配列 [start, end] を返します。

...のオフセットの
配列 [start, end] を返します。

n番目の部分文字列がマッチしていなければ [nil, nil] を返します。

@param n 部分文字列を指定する数値

@raise IndexError 範囲外の n を指定した場合に発生します。

@see MatchData#offset...

MatchData#byteoffset(name) -> [Integer, Integer] | [nil, nil] (6301.0)

name という名前付きグループに対応する部分文字列のバイト単位のオフセットの 配列 [start, end] を返します。

...name という名前付きグループに対応する部分文字列のバイト単位のオフセットの
配列 [start, end] を返します。

nameの名前付きグループにマッチした部分文字列がなければ
[nil, nil] を返します。

@param name 名前(シンボルか文字...
...ます。

//emlist[例][ruby]{
/(?<year>\d{4})年(?<month>\d{1,2})月(?:(?<day>\d{1,2})日)?/ =~ "2021年1月"
p $~.byteoffset('year') # => [0, 4]
p $~.byteoffset(:year) # => [0, 4]
p $~.byteoffset('month') # => [7, 8]
p $~.byteoffset(:month) # => [7, 8]
p $~.byteoffset('day') # =>...
...[nil, nil]
p $~.byteoffset('century') # => `offset': undefined group name reference: century (IndexError)
//}

@see MatchData#offset...

MatchData#deconstruct -> [String] (6201.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#string -> String (6201.0)

マッチ対象になった文字列の複製を返します。

...マッチ対象になった文字列の複製を返します。

返す文字列はフリーズ(Object#freeze)されています。

//emlist[例][ruby]{
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.string # => "THX1138."
//}...

MatchData#captures -> [String] (6101.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_keys(array_of_names) -> Hash (6101.0)

引数で指定された名前の名前付きキャプチャを Hash で返します。

...プチャを意味します。

//emlist[例][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#inspect -> String (6101.0)

self の内容を人間に読みやすい文字列にして返します。

...ist[例][ruby]{
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
# => #<Match...
...Data "hog" foo:"h" bar:"o" baz:"g">
//}...

MatchData#length -> Integer (6101.0)

部分文字列の数を返します(self.to_a.size と同じです)。

...部分文字列の数を返します(self.to_a.size と同じです)。

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.size # => 4
//}...

絞り込み条件を変える

MatchData#named_captures -> Hash (6101.0)

名前付きキャプチャをHashで返します。

...emlist[例][ruby]{
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"}
//}

@see MatchData#captures...
...# => {"a" => "x"}
//}

@see MatchData#captures, MatchData#deconstruct_keys...

MatchData#named_captures(symbolize_names: false) -> Hash (6101.0)

名前付きキャプチャをHashで返します。

...emlist[例][ruby]{
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#offset(n) -> [Integer, Integer] | [nil, nil] (6101.0)

n 番目の部分文字列のオフセットの配列 [start, end] を返 します。

...n 番目の部分文字列のオフセットの配列 [start, end] を返
します。

//emlist[例][ruby]{
[ self.begin(n), self.end(n) ]
//}

と同じです。n番目の部分文字列がマッチしていなければ
[nil, nil] を返します。

@param n 部分文字列を指定する数値...
...@raise IndexError 範囲外の n を指定した場合に発生します。

@see MatchData#begin, MatchData#end...
...@raise IndexError 範囲外の n を指定した場合に発生します。

@see MatchData#begin, MatchData#end, MatchData#offset...
<< 1 2 3 > >>