るりまサーチ

最速Rubyリファレンスマニュアル検索!
2件ヒット [1-2件を表示] (0.011秒)
トップページ > クラス:Regexp[x] > クエリ:MatchData#offset[x]

ライブラリ

検索結果

Regexp#match(str, pos = 0) -> MatchData | nil (148)

指定された文字列 str に対して 位置 pos から 自身が表す正規表現によるマッチングを行います。マッチした場合には結果を MatchData オブジェクトで返します。 マッチしなかった場合 nil を返します。

...列 str に対して
位置 pos から
自身が表す正規表現によるマッチングを行います。マッチした場合には結果を MatchData オブジェクトで返します。
マッチしなかった場合 nil を返します。

省略可能な第二引数 pos を指定すると、...
...(/(.).(.)/.match("foobar", 3).captures) # => ["b", "r"]
p(/(.).(.)/.match("foobar", -3).captures) # => ["b", "r"]

pos を指定しても MatchData#offset 等の結果
には影響しません。つまり、
re.match(str[pos..-1])

re.match(str, pos)
は異なります。

@param str 文...
...ら行うよう制御できます(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") #=> nil

p /(foo)(bar)(baz)/.match("foobarbaz").to_a....