ライブラリ
- English (22)
- ビルトイン (323)
- csv (11)
-
irb
/ cmd / help (11) - optparse (22)
-
rdoc
/ parser (11) -
rubygems
/ spec _ fetcher (22) - strscan (33)
クラス
-
Gem
:: SpecFetcher (22) -
IRB
:: ExtendCommand :: Help (11) - MatchData (92)
- OptionParser (22)
-
RDoc
:: Parser (11) - Regexp (66)
- StringScanner (33)
モジュール
- 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) -
$ LAST _ MATCH _ INFO (11) -
$ LAST _ PAREN _ MATCH (11) -
$ ` (11) -
$ ~ (11) -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - =~ (11)
- CSV (11)
-
NEWS for Ruby 2
. 2 . 0 (10) -
NEWS for Ruby 3
. 0 . 0 (4) -
NEWS for Ruby 3
. 1 . 0 (3) - [] (44)
- accept (22)
- begin (11)
- byteoffset (4)
- execute (11)
- fetch (11)
-
find
_ matching (11) - irb (11)
-
last
_ match (22) - match? (11)
-
matched
_ size (11) - offset (22)
-
parse
_ files _ matching (11) -
rexml
/ document (11) -
ruby 1
. 6 feature (11) -
ruby 1
. 8 . 4 feature (11) -
ruby 1
. 9 feature (11) - unscan (11)
- ~ (11)
- クラス/メソッドの定義 (11)
検索結果
先頭5件
-
MatchData
# end(n) -> Integer | nil (21237.0) -
n 番目の部分文字列終端のオフセットを返します。
...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 (18416.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)
//}
は異なります。......ルト値は 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 (18316.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)
//}
は異なります。......ルト値は 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"]
//}
===... -
Gem
:: SpecFetcher # find _ matching(dependency , all = false , matching _ platform = true) -> Array (6400.0) -
依存関係を満たす gemspec の名前の配列を返します。
...返します。
@param dependency 依存関係を指定します。
@param all 真を指定するとマッチする全てのバージョンの情報を返します。
@param matching_platform 偽を指定すると全てのプラットフォームの情報を返します。
@see Gem::Dependency... -
Regexp
. last _ match -> MatchData (6344.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
//}... -
Kernel
$ $ LAST _ MATCH _ INFO -> MatchData | nil (6343.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(nth) -> String | nil (6279.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 番目の括弧にマッチした部分文字列を返します。... -
StringScanner
# match?(regexp) -> Integer | nil (6237.0) -
スキャンポインタの地点だけで regexp と文字列のマッチを試します。 マッチしたら、スキャンポインタは進めずにマッチした 部分文字列の長さを返します。マッチしなかったら nil を 返します。
...e))
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+/... -
StringScanner
# matched _ size -> Integer | nil (6218.0) -
前回マッチした部分文字列の長さを返します。 前回マッチに失敗していたら nil を返します。
...e)}/)
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 #... -
Kernel
$ $ LAST _ PAREN _ MATCH -> String | nil (6213.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....