関連するキーワード
ライブラリ
- ビルトイン (3)
検索結果
-
Regexp
# match(str) -> MatchData | nil (13) -
指定された文字列 str に対して 自身が表す正規表現によるマッチングを行います。マッチした場合には結果を MatchData オブジェクトで返します。 マッチしなかった場合 nil を返します。
...た場合 nil を返します。
@param str 文字列を指定します。str との正規表現マッチを行います。
使用例
reg = Regexp.new("foo")
if reg.match("foobar")
print "match\n" #=> match
end
p reg.match("foobar") #=> #<MatchData:0x29403fc>
p reg.match("bar")......ませんが、captures では、マッチに失敗した場合、
nil.captures を呼び出そうとして例外 NoMethodError が発生して
しまいます。
foo, bar, baz = /(foo)(bar)(baz)/.match("foobar").captures
# => -:1: undefined method `captures' for nil:NilClass (NoMethodError)... -
Regexp
# match(str , pos = 0) -> MatchData | nil (13) -
指定された文字列 str に対して 位置 pos から 自身が表す正規表現によるマッチングを行います。マッチした場合には結果を MatchData オブジェクトで返します。 マッチしなかった場合 nil を返します。
...数を指定します。マッチの開始位置を pos から行うよう制御できます(pos のデフォルト値は 0)。
使用例
reg = Regexp.new("foo")
if reg.match("foobar")
print "match\n" #=> match
end
p reg.match("foobar") #=> #<MatchData:0x29403fc>
p reg.match("bar")......ませんが、captures では、マッチに失敗した場合、
nil.captures を呼び出そうとして例外 NoMethodError が発生して
しまいます。
foo, bar, baz = /(foo)(bar)(baz)/.match("foobar").captures
# => -:1: undefined method `captures' for nil:NilClass (NoMethodError)...
