るりまサーチ

最速Rubyリファレンスマニュアル検索!
483件ヒット [1-100件を表示] (0.054秒)
トップページ > クエリ:nil[x] > クエリ:end[x] > クエリ:match[x]

別のキーワード

  1. _builtin nil?
  2. nilclass nil?
  3. object nil?
  4. _builtin nil
  5. object nil

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

MatchData#end(n) -> Integer | nil (21250.0)

n 番目の部分文字列終端のオフセットを返します。

... nil を返します。

@param n 部分文字列を指定する数値。

@raise IndexError 範囲外の n を指定した場合に発生します。

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.end(0) # => 6
p $~.end(1) # => 3
p $~.end(2) # => 6
p $~.end(3) # => nil
p $~...
....end(4) # => `end': index 4 out of matches (IndexError)
//}

@see MatchData#begin...

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

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

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

省略可能な第二引数 pos を指定すると、マッチの開始位置を 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)
//}
は異なります。...
...ルト値は 0)。

//emlist[例][ruby]{
reg = Regexp.new("foo")

if reg.match("foobar")
puts "match"
end

# => match

p reg.match("foobar") # => #<MatchData:0x29403fc>
p reg.match("bar") # => nil

p /(foo)(bar)(baz)/.match("foobarbaz").to_a.values_at(1,2,3) # => ["foo", "bar", "baz"]
//}

===...

Regexp#match(str, pos = 0) {|m| ... } -> object | nil (18358.0)

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

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

省略可能な第二引数 pos を指定すると、マッチの開始位置を 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)
//}
は異なります。...
...ルト値は 0)。

//emlist[例][ruby]{
reg = Regexp.new("foo")

if reg.match("foobar")
puts "match"
end

# => match

p reg.match("foobar") # => #<MatchData:0x29403fc>
p reg.match("bar") # => nil

p /(foo)(bar)(baz)/.match("foobarbaz").to_a.values_at(1,2,3) # => ["foo", "bar", "baz"]
//}

===...

Regexp.last_match(nth) -> String | nil (6333.0)

整数 nth が 0 の場合、マッチした文字列を返します ($&)。それ以外では、nth 番目の括弧にマッチ した部分文字列を返します($1,$2,...)。 対応する括弧がない場合やマッチしなかった場合には nil を返し ます。

...なかった場合には nil を返し
ます。

//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
//}

正規表現全...
...exp.last_matchnil を返すため、
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 番目の括弧にマッチした部分文...

Kernel$$LAST_MATCH_INFO -> MatchData | nil (6332.0)

$~ の別名

...f=https://www.ruby-lang.org/en/about/license.txt>license</a>"

if /<a href=(.+?)>/ =~ str
p $LAST_MATCH_INFO[0] #=> "<a href=https://www.ruby-lang.org/en/about/license.txt>"
p $LAST_MATCH_INFO[1] #=> "https://www.ruby-lang.org/en/about/license.txt"
p $LAST_MATCH_INFO[2] #=> nil
end
...

絞り込み条件を変える

Regexp.last_match -> MatchData (6258.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
//}...

StringScanner#match?(regexp) -> Integer | nil (6254.0)

スキャンポインタの地点だけで regexp と文字列のマッチを試します。 マッチしたら、スキャンポインタは進めずにマッチした 部分文字列の長さを返します。マッチしなかったら nil を 返します。

...たら nil
返します。

マッチしたサイズは文字単位でなくバイト単位となります。

//emlist[][ruby]{
require 'strscan'
def case1(encode)
utf8 = "\u{308B 3073 3044}"
s = StringScanner.new(utf8.encode(encode))
s.match?(/#{"\u{308B}".encode(encode)}/)
end


p case1(...
..."EUC-JP") #=> 2
//}

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

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

s = StringScanner.new('test string')
p s.match?(/\w+/) #=> 4
p s.match?(/\w+/) #=> 4
p s.match?(/\s+/) #=> nil
//}...

StringScanner#matched_size -> Integer | nil (6241.0)

前回マッチした部分文字列の長さを返します。 前回マッチに失敗していたら nil を返します。

... nil を返します。

マッチしたサイズは文字単位でなくバイト単位となります。

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

def run(encode)
utf8 = "\u{308B 3073 3044}" # るびい
s = StringScanner.new(utf8.encode(encode))
s.scan(/#{"\u{308B}".encode(encode)}/)
s.matched...
..._size
end


p run("UTF-8") #=> 3
p run("EUC-JP") #=> 2
p run("Shift_Jis") #=> 2

//}

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

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

Kernel$$LAST_PAREN_MATCH -> String | nil (6214.0)

$+ の別名

...r2 = Regexp.compile("<a href=(http|ftp).+?>(.+?)</a>")

while line = DATA.gets
[ r1, r2 ].each {|rep|
rep =~ line
p $+
}
end

__END__
<tr> <td><img src=http://localhost/a.jpg></td> <td>ikkou</td> <td><a href=http://localhost/link.html>link</a></td> </tr>
#enf of sample....

MatchData#offset(name) -> [Integer, Integer] | [nil, nil] (3261.0)

name という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返 します。

...部分文字列のオフセットの配列 [start, end] を返
します。

//emlist[例][ruby]{
[ self.begin(name), self.end(name) ]
//}

と同じです。nameの名前付きグループにマッチした部分文字列がなければ
[nil, nil] を返します。

@param name 名前(シンボル...
...0, 4]
p $~.offset(:year) # => [0, 4]
p $~.offset('month') # => [5, 6]
p $~.offset(:month) # => [5, 6]
p $~.offset('day') # => [nil, nil]
p $~.offset('century') # => `offset': undefined group name reference: century (IndexError)
//}

@see MatchData#begin, MatchData#end, MatchData#offset...

絞り込み条件を変える

<< 1 2 3 ... > >>