るりまサーチ

最速Rubyリファレンスマニュアル検索!
224件ヒット [1-100件を表示] (0.120秒)
トップページ > 種類:インスタンスメソッド[x] > クエリ:p[x] > クエリ:g[x] > クラス:MatchData[x]

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. dh p
  5. rsa p

ライブラリ

キーワード

検索結果

<< 1 2 3 > >>

MatchData#regexp -> Regexp (12402.0)

自身の元になった正規表現オブジェクトを返します。

...自身の元になった正規表現オブジェクトを返します。

//emlist[例][ruby]{
m = /a.*b/.match("abc")
m.regexp # => /a.*b/
//}...

MatchData#captures -> [String] (6214.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#inspect -> String (6208.0)

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

...y]{
p
uts /.$/.match("foo").inspect
# => #<MatchData "o">

p
uts /(.)(.)(.)/.match("foo").inspect
# => #<MatchData "foo" 1:"f" 2:"o" 3:"o">

p
uts /(.)(.)?(.)/.match("fo").inspect
# => #<MatchData "fo" 1:"f" 2:nil 3:"o">

p
uts /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").inspect
# => #<MatchData "hog" f...
...oo:"h" bar:"o" baz:"g">
//}...

MatchData#post_match -> String (6208.0)

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

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

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

@see MatchData#pre_match...

MatchData#pre_match -> String (6208.0)

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

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

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

@see MatchData#post_match...

絞り込み条件を変える

MatchData#begin(n) -> Integer | nil (6132.0)

n 番目の部分文字列先頭のオフセットを返します。

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

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

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p
$~.begin(0) # => 0
p
$~.begin(1) # => 0
p
$~.begin(2) # => 3
p
$~.begin(3) # => nil
p
$~.begin(4) # => `beg...
...in': index 4 out of matches (IndexError)
//}

@see MatchData#end...

MatchData#length -> Integer (6108.0)

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

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

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

MatchData#deconstruct -> [String] (3114.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#size -> Integer (3108.0)

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

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

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

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

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

...@param name 名前(シンボルか文字列)

@raise IndexError 正規表現中で定義されていない 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...

絞り込み条件を変える

<< 1 2 3 > >>