ライブラリ
- English (12)
- ビルトイン (442)
-
irb
/ cmd / help (12) -
ripper
/ lexer (12)
キーワード
-
$ LAST _ MATCH _ INFO (12) -
$ ~ (12) -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) - == (12)
- =~ (12)
-
NEWS for Ruby 2
. 4 . 0 (9) -
NEWS for Ruby 3
. 1 . 0 (4) - [] (48)
- begin (12)
- byteoffset (6)
- byterindex (3)
- captures (12)
- deconstruct (2)
-
deconstruct
_ keys (2) - dump (24)
- end (12)
- eql? (12)
- execute (12)
- hash (12)
- inspect (12)
-
last
_ match (24) - length (12)
- match (57)
-
named
_ captures (12) - names (12)
- offset (24)
-
post
_ match (12) -
pre
_ match (12) - regexp (12)
-
ruby 1
. 6 feature (12) -
ruby 1
. 9 feature (12) - size (12)
- string (12)
-
to
_ a (12) -
to
_ s (12) -
token
_ match (12) -
values
_ at (12) - パターンマッチ (3)
- 正規表現 (12)
検索結果
先頭5件
-
MatchData (44000.0)
-
正規表現のマッチに関する情報を扱うためのクラス。
...正規表現のマッチに関する情報を扱うためのクラス。
このクラスのインスタンスは、
* Regexp.last_match
* Regexp#match, String#match
* $~
などにより得られます。... -
MatchData
# post _ match -> String (30106.0) -
マッチした部分より後ろの文字列を返します($'と同じ)。
...マッチした部分より後ろの文字列を返します($'と同じ)。
//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.post_match # => "baz"
//}
@see MatchData#pre_match... -
MatchData
# pre _ match -> String (30106.0) -
マッチした部分より前の文字列を返します($`と同じ)。
...マッチした部分より前の文字列を返します($`と同じ)。
//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.pre_match # => "foo"
//}
@see MatchData#post_match... -
MatchData
# byteoffset(n) -> [Integer , Integer] | [nil , nil] (27307.0) -
n 番目の部分文字列のバイト単位のオフセットの 配列 [start, end] を返します。
...のオフセットの
配列 [start, end] を返します。
n番目の部分文字列がマッチしていなければ [nil, nil] を返します。
@param n 部分文字列を指定する数値
@raise IndexError 範囲外の n を指定した場合に発生します。
@see MatchData#offset... -
MatchData
# byteoffset(name) -> [Integer , Integer] | [nil , nil] (27307.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] (27218.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 (27200.0) -
マッチ対象になった文字列の複製を返します。
...マッチ対象になった文字列の複製を返します。
返す文字列はフリーズ(Object#freeze)されています。
//emlist[例][ruby]{
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.string # => "THX1138."
//}... -
MatchData
# inspect -> String (27124.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
# offset(n) -> [Integer , Integer] | [nil , nil] (27121.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, MatchData#offset... -
MatchData
# offset(name) -> [Integer , Integer] | [nil , nil] (27121.0) -
name という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返 します。
...name という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返
します。
//emlist[例][ruby]{
[ self.begin(name), self.end(name) ]
//}
と同じです。nameの名前付きグループにマッチした部分文字列がなければ
[nil, ni......emlist[例][ruby]{
/(?<year>\d{4})年(?<month>\d{1,2})月(?:(?<day>\d{1,2})日)?/ =~ "2021年1月"
p $~.offset('year') # => [0, 4]
p $~.offset(:year) # => [0, 4]
p $~.offset('month') # => [5, 6]
p $~.offset(:month) # => [5, 6]
p $~.offset('day') # => [nil, nil]
p $~.offset('century')......# => `offset': undefined group name reference: century (IndexError)
//}
@see MatchData#begin, MatchData#end, MatchData#offset... -
MatchData
# captures -> [String] (27118.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
# offset(n) -> [Integer , Integer] | [nil , nil] (27114.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... -
MatchData
# offset(name) -> [Integer , Integer] | [nil , nil] (27114.0) -
name という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返 します。
...name という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返
します。
//emlist[例][ruby]{
[ self.begin(name), self.end(name) ]
//}
と同じです。nameの名前付きグループにマッチした部分文字列がなければ
[nil, ni......emlist[例][ruby]{
/(?<year>\d{4})年(?<month>\d{1,2})月(?:(?<day>\d{1,2})日)?/ =~ "2021年1月"
p $~.offset('year') # => [0, 4]
p $~.offset(:year) # => [0, 4]
p $~.offset('month') # => [5, 6]
p $~.offset(:month) # => [5, 6]
p $~.offset('day') # => [nil, nil]
p $~.offset('century')......# => `offset': undefined group name reference: century (IndexError)
//}
@see MatchData#begin, MatchData#end...