モジュール
-
File
:: Constants (11) - Kernel (187)
キーワード
-
$ & (11) -
$ & # 39; (11) -
$ 1 (11) -
$ 10 (11) -
$ 11 (11) -
$ 2 (11) -
$ 3 (11) -
$ 4 (11) -
$ 5 (11) -
$ 6 (11) -
$ 7 (11) -
$ 8 (11) -
$ 9 (11) -
$ ` (11) -
$ ~ (11) - == (11)
- =~ (11)
- EPROGMISMATCH (11)
- ERPCMISMATCH (11)
-
FNM
_ DOTMATCH (11) - MatchData (11)
- NoMatchingPatternError (5)
- Regexp (11)
-
SCRIPT
_ LINES _ _ (11) - [] (44)
- begin (11)
- byteoffset (4)
- captures (11)
- compile (11)
- end (11)
- eql? (11)
- fnmatch (11)
- fnmatch? (11)
- gsub (22)
- gsub! (11)
- hash (11)
- inspect (11)
-
last
_ match (22) - length (11)
- match? (24)
-
named
_ captures (11) - names (11)
- new (11)
- offset (22)
-
post
_ match (11) -
pre
_ match (11) - regexp (11)
- size (11)
- string (11)
- sub (22)
- sub! (11)
-
to
_ a (11) -
to
_ s (11) -
values
_ at (11) - ~ (11)
検索結果
先頭5件
-
String
# match(regexp , pos = 0) -> MatchData | nil (26314.0) -
regexp.match(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match を参照してください。
...regexp.match(self, pos) と同じです。
regexp が文字列の場合は、正規表現にコンパイルします。
詳しくは Regexp#match を参照してください。
//emlist[例: regexp のみの場合][ruby]{
'hello'.match('(.)\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 hege bar'.match('h.ge', 1) # => #<MatchData "hige">
//}
//emlis......t[例: ブロックを指定した場合][ruby]{
'hello'.match('(.)\1'){|e|"match #{$1}"} # => "match l"
'hello'.match('xx'){|e|"match #{$1}"} # マッチしないためブロックは実行されない
//}
@see Regexp#match, Symbol#match... -
Regexp
# match(str , pos = 0) -> MatchData | nil (26306.0) -
指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。
...字列 str に対して位置 pos から自身が表す正規表現によるマッ
チングを行います。マッチした場合には結果を MatchData オブジェクトで返し
ます。
マッチしなかった場合 nil を返します。
省略可能な第二引数 pos を指定すると......captures) # => ["b", "r"]
p(/(.).(.)/.match("foobar", -3).captures) # => ["b", "r"]
//}
pos を指定しても MatchData#offset 等の結果
には影響しません。つまり、
//emlist[][ruby]{
re.match(str[pos..-1])
//}
と
//emlist[][ruby]{
re.match(str, pos)
//}
は異なります。......チした場合に限り MatchData オブジェクトがブロック引数に渡されて実行されます。
マッチした場合はブロックの値を返し、マッチしなかった場合は nil を返します。
//emlist[例][ruby]{
results = []
/((.)\2)/.match("foo") {|m| results << m[0]... -
Symbol
# match(other) -> MatchData | nil (26239.0) -
正規表現 other とのマッチを行います。
....match(other) と同じです。)
@param other 比較対象のシンボルを指定します。
@return マッチが成功すれば MatchData オブジェクトを、そうでなければ nil を返します。
p :foo.match(/foo/) # => #<MatchData "foo">
p :foobar.match(/bar/) # => #<Match......Data "bar">
p :foo.match(/bar/) # => nil
@see String#match
@see Symbol#match?... -
String
# match(regexp , pos = 0) {|m| . . . } -> object (26214.0) -
regexp.match(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match を参照してください。
...regexp.match(self, pos) と同じです。
regexp が文字列の場合は、正規表現にコンパイルします。
詳しくは Regexp#match を参照してください。
//emlist[例: regexp のみの場合][ruby]{
'hello'.match('(.)\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 hege bar'.match('h.ge', 1) # => #<MatchData "hige">
//}
//emlis......t[例: ブロックを指定した場合][ruby]{
'hello'.match('(.)\1'){|e|"match #{$1}"} # => "match l"
'hello'.match('xx'){|e|"match #{$1}"} # マッチしないためブロックは実行されない
//}
@see Regexp#match, Symbol#match... -
Regexp
# match(str , pos = 0) {|m| . . . } -> object | nil (26206.0) -
指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。
...字列 str に対して位置 pos から自身が表す正規表現によるマッ
チングを行います。マッチした場合には結果を MatchData オブジェクトで返し
ます。
マッチしなかった場合 nil を返します。
省略可能な第二引数 pos を指定すると......captures) # => ["b", "r"]
p(/(.).(.)/.match("foobar", -3).captures) # => ["b", "r"]
//}
pos を指定しても MatchData#offset 等の結果
には影響しません。つまり、
//emlist[][ruby]{
re.match(str[pos..-1])
//}
と
//emlist[][ruby]{
re.match(str, pos)
//}
は異なります。......チした場合に限り MatchData オブジェクトがブロック引数に渡されて実行されます。
マッチした場合はブロックの値を返し、マッチしなかった場合は nil を返します。
//emlist[例][ruby]{
results = []
/((.)\2)/.match("foo") {|m| results << m[0]... -
Symbol
# match(other) -> Integer | nil (26133.0) -
正規表現 other とのマッチを行います。
...elf.to_s.match(other) と同じです。)
@param other 比較対象のシンボルを指定します。
@return マッチが成功すればマッチした位置を、そうでなければ nil を返します。
p :foo.match(/foo/) # => 0
p :foobar.match(/bar/) # => 3
p :foo.match(/bar/)......# => nil
@see String#match... -
MatchData
# post _ match -> String (17115.0) -
マッチした部分より後ろの文字列を返します($'と同じ)。
...マッチした部分より後ろの文字列を返します($'と同じ)。
//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.post_match # => "baz"
//}
@see MatchData#pre_match... -
MatchData
# pre _ match -> String (17115.0) -
マッチした部分より前の文字列を返します($`と同じ)。
...マッチした部分より前の文字列を返します($`と同じ)。
//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.pre_match # => "foo"
//}
@see MatchData#post_match... -
Regexp
. last _ match -> MatchData (14245.0) -
カレントスコープで最後に行った正規表現マッチの MatchData オ ブジェクトを返します。このメソッドの呼び出しは $~ の参照と同じです。
... MatchData オ
ブジェクトを返します。このメソッドの呼び出しは $~
の参照と同じです。
//emlist[例][ruby]{
/(.)(.)/ =~ "ab"
p Regexp.last_match # => #<MatchData:0x4599e58>
p Regexp.last_match[0] # => "ab"
p Regexp.last_match[1] # => "a"
p Regexp.last_match[2]......# => "b"
p Regexp.last_match[3] # => nil
//}... -
Symbol
# match?(regexp , pos = 0) -> bool (14177.0) -
regexp.match?(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match? を参照してください。
...regexp.match?(self, pos) と同じです。
regexp が文字列の場合は、正規表現にコンパイルします。
詳しくは Regexp#match? を参照してください。
例:
:Ruby.match?(/R.../) # => true
:Ruby.match?('Ruby') # => true
:Ruby.match?('Ruby',1) # => false
:R......uby.match?('uby',1) # => true
:Ruby.match?(/P.../) # => false
$& # => nil
@see Regexp#match?, String#match?... -
Regexp
. last _ match(nth) -> String | nil (14175.0) -
整数 nth が 0 の場合、マッチした文字列を返します ($&)。それ以外では、nth 番目の括弧にマッチ した部分文字列を返します($1,$2,...)。 対応する括弧がない場合やマッチしなかった場合には nil を返し ます。
..."
p Regexp.last_match # => #<MatchData:0x4599e58>
p Regexp.last_match(0) # => "ab"
p Regexp.last_match(1) # => "a"
p Regexp.last_match(2) # => "b"
p Regexp.last_match(3) # => nil
//}
正規表現全体がマッチしなかった場合、引数なしの
Regexp.last_match はnil を返......すため、
last_match[1] の形式では例外 NoMethodError が発生します。
対して、last_match(1) は nil を返します。
//emlist[例][ruby]{
str = "This is Regexp"
/That is Regexp/ =~ str
p Regexp.last_match # => nil
begin
p Regexp.last_match[1] # 例外が発生する
rescue......puts $! # => undefined method `[]' for nil:NilClass
end
p Regexp.last_match(1) # => nil
//}
@param nth 整数を指定します。
整数 nth が 0 の場合、マッチした文字列を返します。それ以外では、nth 番目の括弧にマッチした部分文字列を返します。...