るりまサーチ

最速Rubyリファレンスマニュアル検索!
1608件ヒット [201-300件を表示] (0.031秒)

別のキーワード

  1. _builtin match
  2. _builtin match?
  3. string match
  4. regexp match
  5. regexp last_match

キーワード

検索結果

<< < 1 2 3 4 5 ... > >>

Symbol#match?(regexp, pos = 0) -> bool (6175.0)

regexp.match?(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match? を参照してください。

...regexp.match?(self, pos) と同じです。
regexp が文字列の場合は、正規表現にコンパイルします。
詳しくは Regexp#match? を参照してください。

例:

:Ruby.match?(/R.../) # => true
:Ruby.match?('Ruby') # => true
:Ruby.match?('Ruby',1) # => false
:R...
...uby.match?('uby',1) # => true
:Ruby.match?(/P.../) # => false
$& # => nil

@see Regexp#match?, String#match?...

Regexp.last_match(nth) -> String | nil (6173.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 番目の括弧にマッチした部分文字列を返します。...

String#match?(regexp, pos = 0) -> bool (6163.0)

regexp.match?(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match? を参照してください。

...regexp.match?(self, pos) と同じです。
regexp が文字列の場合は、正規表現にコンパイルします。
詳しくは Regexp#match? を参照してください。

//emlist[例][ruby]{
"Ruby".match?(/R.../) #=> true
"Ruby".match?(/R.../, 1) #=> false
"Ruby".match?(/P.../) #=>...
...false
$& #=> nil
//}

@see Regexp#match?, Symbol#match?...

StringScanner#post_match -> String | nil (6137.0)

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

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

StringScanner#pre_match -> String | nil (6137.0)

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

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

絞り込み条件を変える

Regexp#match?(str, pos = 0) -> bool (6125.0)

指定された文字列 str に対して 位置 pos から自身が表す正規表現によるマッチングを行います。 マッチした場合 true を返し、マッチしない場合には false を返します。 また、$~ などパターンマッチに関する組み込み変数の値は変更されません。

...ます。
また、$~ などパターンマッチに関する組み込み変数の値は変更されません。

//emlist[例][ruby]{
/R.../.match?("Ruby") # => true
/R.../.match?("Ruby", 1) # => false
/P.../.match?("Ruby") # => false
$& # => nil
//}

@see Regexp#match...

StringScanner#match?(regexp) -> Integer | nil (6125.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+/...

Kernel$$MATCH -> String | nil (6107.0)

$& の別名

...$& の別名

require "English"

str = 'hoge,foo,bar,hee,hoo'

/(foo|bar)/ =~ str
p $MATCH #=> "foo"...

Object#must_match(regexp) -> true (6107.0)

自身が与えられた正規表現にマッチした場合、検査にパスしたことになります。

...文字列を指定した場合は文字列そのものにマッチする
正規表現に変換してから使用します。

@raise MiniTest::Assertion 自身が与えられた正規表現にマッチしなかった場合に発生します。

@see MiniTest::Assertions#assert_match...

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

$+ の別名

$+ の別名

require "English"

r1 = Regexp.compile("<img src=(http:.+?)>")
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>...

絞り込み条件を変える

MiniTest::Assertions#assert_match(regexp, str, message = nil) -> true (6101.0)

与えられた文字列が与えられた正規表現にマッチした場合、検査にパスしたことになります。

与えられた文字列が与えられた正規表現にマッチした場合、検査にパスしたことになります。

@param regexp 正規表現か文字列を指定します。文字列を指定した場合は文字列そのものにマッチする
正規表現に変換してから使用します。

@param str 検査対象の文字列を指定します。

@param message 検査に失敗した場合に表示するメッセージを指定します。
文字列か Proc を指定します。Proc である場合は Proc#call した
結果を使用します。

@raise MiniTest...

Scanf::FormatSpecifier#mid_match? (6101.0)

@todo

@todo

Scanf::FormatString#last_match_tried (6101.0)

@todo

@todo
<< < 1 2 3 4 5 ... > >>