318件ヒット
[1-100件を表示]
(0.041秒)
ライブラリ
- ビルトイン (241)
-
irb
/ cmd / help (11)
クラス
-
IRB
:: ExtendCommand :: Help (11) - MatchData (143)
- Regexp (33)
- String (24)
- Symbol (8)
モジュール
- Marshal (22)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - =~ (11)
-
NEWS for Ruby 2
. 4 . 0 (8) -
NEWS for Ruby 3
. 1 . 0 (3) - [] (44)
- byterindex (2)
- captures (11)
- dump (22)
- execute (11)
- inspect (11)
- irb (11)
-
last
_ match (22) - match (30)
- names (11)
-
post
_ match (11) -
pre
_ match (11) -
ruby 1
. 6 feature (11) -
ruby 1
. 9 feature (11) - string (11)
-
to
_ a (11) -
to
_ s (11) -
values
_ at (11) - 正規表現 (11)
検索結果
先頭5件
-
MatchData (38006.0)
-
正規表現のマッチに関する情報を扱うためのクラス。
...正規表現のマッチに関する情報を扱うためのクラス。
このクラスのインスタンスは、
* Regexp.last_match
* Regexp#match, String#match
* $~
などにより得られます。... -
MatchData
# string -> String (27208.0) -
マッチ対象になった文字列の複製を返します。
...マッチ対象になった文字列の複製を返します。
返す文字列はフリーズ(Object#freeze)されています。
//emlist[例][ruby]{
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.string # => "THX1138."
//}... -
MatchData
# inspect -> String (21125.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] (21119.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... -
String
# match(regexp , pos = 0) -> MatchData | nil (21119.0) -
regexp.match(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match を参照してください。
...h('(.)\1') # => #<MatchData "ll" 1:"l">
'hello'.match('(.)\1')[0] # => "ll"
'hello'.match(/(.)\1/)[0] # => "ll"
'hello'.match('xx') # => nil
//}
//emlist[例: regexp, pos を指定した場合][ruby]{
'hoge hige hege bar'.match('h.ge', 0) # => #<MatchData "hoge">
'hoge hige heg......e bar'.match('h.ge', 1) # => #<MatchData "hige">
//}
//emlist[例: ブロックを指定した場合][ruby]{
'hello'.match('(.)\1'){|e|"match #{$1}"} # => "match l"
'hello'.match('xx'){|e|"match #{$1}"} # マッチしないためブロックは実行されない
//}
@see Regexp#match, Sym... -
MatchData
# names -> [String] (21107.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 (21107.0) -
マッチした部分より後ろの文字列を返します($'と同じ)。
...マッチした部分より後ろの文字列を返します($'と同じ)。
//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.post_match # => "baz"
//}
@see MatchData#pre_match... -
MatchData
# pre _ match -> String (21107.0) -
マッチした部分より前の文字列を返します($`と同じ)。
...マッチした部分より前の文字列を返します($`と同じ)。
//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.pre_match # => "foo"
//}
@see MatchData#post_match... -
MatchData
# to _ a -> [String] (21107.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 (21107.0) -
マッチした文字列全体を返します。
...マッチした文字列全体を返します。
//emlist[例][ruby]{
/bar/ =~ "foobarbaz"
p $~ # => #<MatchData:0x401b1be4>
p $~.to_s # => "bar"
//}...