143件ヒット
[1-100件を表示]
(0.083秒)
ライブラリ
- ビルトイン (143)
検索結果
先頭5件
-
MatchData
# string -> String (35210.0) -
マッチ対象になった文字列の複製を返します。
...マッチ対象になった文字列の複製を返します。
返す文字列はフリーズ(Object#freeze)されています。
//emlist[例][ruby]{
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.string # => "THX1138."
//}... -
MatchData
# inspect -> String (17127.0) -
self の内容を人間に読みやすい文字列にして返します。
...ch("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:"h" bar:"o" ba... -
MatchData
# captures -> [String] (17121.0) -
$1, $2, ... を格納した配列を返します。
...$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... -
MatchData
# names -> [String] (17109.0) -
名前付きキャプチャの名前を文字列配列で返します。
...前を文字列配列で返します。
self.regexp.names と同じです。
//emlist[例][ruby]{
/(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").names
# => ["foo", "bar", "baz"]
m = /(?<x>.)(?<y>.)?/.match("a") # => #<MatchData "a" x:"a" y:nil>
m.names # => ["x", "y"]
//}... -
MatchData
# post _ match -> String (17109.0) -
マッチした部分より後ろの文字列を返します($'と同じ)。
...マッチした部分より後ろの文字列を返します($'と同じ)。
//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.post_match # => "baz"
//}
@see MatchData#pre_match... -
MatchData
# pre _ match -> String (17109.0) -
マッチした部分より前の文字列を返します($`と同じ)。
...マッチした部分より前の文字列を返します($`と同じ)。
//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.pre_match # => "foo"
//}
@see MatchData#post_match... -
MatchData
# to _ a -> [String] (17109.0) -
$&, $1, $2,... を格納した配列を返します。
...$&, $1, $2,... を格納した配列を返します。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
//}
@see MatchData#captures... -
MatchData
# to _ s -> String (17109.0) -
マッチした文字列全体を返します。
...マッチした文字列全体を返します。
//emlist[例][ruby]{
/bar/ =~ "foobarbaz"
p $~ # => #<MatchData:0x401b1be4>
p $~.to_s # => "bar"
//}... -
MatchData
# [](n) -> String | nil (17106.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 (17106.0) -
name という名前付きグループにマッチした文字列を返します。
name という名前付きグループにマッチした文字列を返します。
@param name 名前(シンボルか文字列)
@raise IndexError 指定した名前が正規表現内に含まれていない場合に発生します
//emlist[例][ruby]{
/\$(?<dollars>\d+)\.(?<cents>\d+)/.match("$3.67")[:cents] # => "67"
/(?<alpha>[a-zA-Z]+)|(?<num>\d+)/.match("aZq")[:num] # => nil
//}