るりまサーチ

最速Rubyリファレンスマニュアル検索!
44件ヒット [1-44件を表示] (0.137秒)
トップページ > クエリ:i[x] > クエリ:h[x] > クエリ:pre_match[x]

別のキーワード

  1. _builtin to_h
  2. hash to_h
  3. env to_h
  4. struct to_h
  5. ostruct to_h

ライブラリ

クラス

キーワード

検索結果

StringScanner#pre_match -> String | nil (27337.0)

前回マッチを行った文字列のうち、マッチしたところよりも前の 部分文字列を返します。前回のマッチが失敗していると常に nil を 返します。

...に nil を
返します。

//emlist[例][ruby]{
require 'strscan'

s = StringScanner.new('test string')
s.pre_match # => nil
s.scan(/\w+/) # => "test"
s.pre_match # => ""
s.scan(/\w+/) # => nil
s.pre_match # => nil
s.scan(/\s+/) # => " "
s.pre_match # => "test"
s.scan(/\w+/) # => "string"...
...s.pre_match # => "test "
s.scan(/\w+/) # => nil
s.pre_match # => nil
//}...

MatchData#pre_match -> String (24307.0)

マッチした部分より前の文字列を返します($`と同じ)。

...マッチした部分より前の文字列を返します($`と同じ)。

//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.pre_match # => "foo"
//}

@see MatchData#post_match...

StringScanner#check_until(regexp) -> String | nil (12306.0)

regexp が一致するまで文字列をスキャンします。 マッチに成功したらスキャン開始位置からマッチ部分の末尾までの部分文字列を返します。 マッチに失敗したら nil を返します。

...したら nil を返します。

このメソッドはマッチが成功してもスキャンポインタを進めません。

@param regexp マッチに用いる正規表現を指定します。

//emlist[例][ruby]{
require 'strscan'

s = StringScanner.new('test string')
s.check_until(/str/) # =...
...> "test str"
s.matched # => "str"
s.pos # => 0
s.pre_match # => "test "
//}...

MatchData#post_match -> String (6206.0)

マッチした部分より後ろの文字列を返します($'と同じ)。

...マッチした部分より後ろの文字列を返します($'と同じ)。

//emlist[例][ruby]{
/(bar)(BAZ)?/ =~ "foobarbaz"
p $~.post_match # => "baz"
//}

@see MatchData#pre_match...