るりまサーチ

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

別のキーワード

  1. _builtin last
  2. regexp last_match
  3. _builtin last_match
  4. array last
  5. fiddle last_error

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 > >>

Regexp.last_match(nth) -> String | nil (18273.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
//}

正規表現全体...
...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 番目の括弧にマッチした部分...

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

$~ の別名

...

require "English"

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

i
f /<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...

Scanf::FormatString#last_match_tried (12201.0)

@todo

@todo

Regexp.compile(string, option = nil, code = nil) -> Regexp (6306.0)

文字列 string をコンパイルして正規表現オブジェクトを生成して返します。

...文字列 string をコンパイルして正規表現オブジェクトを生成して返します。

第一引数が正規表現であれば第一引数を複製して返します。第二、第三引数は警告の上無視されます。

@param string 正規表現を文字列として与えま...
...@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp::EXTENDED
の論理和を指定します。
I
nteger 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp::IGNORECASE...
... is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
p $~ # => "This is Regexp"

t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp # ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
p Regexp.last_match...

Regexp.new(string, option = nil, code = nil) -> Regexp (3106.0)

文字列 string をコンパイルして正規表現オブジェクトを生成して返します。

...文字列 string をコンパイルして正規表現オブジェクトを生成して返します。

第一引数が正規表現であれば第一引数を複製して返します。第二、第三引数は警告の上無視されます。

@param string 正規表現を文字列として与えま...
...@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp::EXTENDED
の論理和を指定します。
I
nteger 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp::IGNORECASE...
... is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
p $~ # => "This is Regexp"

t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp # ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
p Regexp.last_match...

絞り込み条件を変える

1.6.8から1.8.0への変更点(まとめ) (546.0)

1.6.8から1.8.0への変更点(まとめ) * ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>)) * ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>)) * ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>)) * ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>)) * ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))

...の変更点(まとめ)/Windows 対応>))
* ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>))
* ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>))
* ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>))
* ((<1.6.8から1.8.0...
...$stderr>)) [change]
: ((<組み込み変数/$stdin>)) [change]

$stdout, $stderr は、$defout, $deferr の別名になり
$defout, $deferr は ((<obsolete>)) になりました

$stdin は、普通のグローバル変数となりました(STDINをリダイレクトする
動作はなく...
...p/Regexp.last_match>)) [compat]
optional な引数が追加されました。

=== String

: ((<String/String.new>)) [compat]

String.new の引数を省略できるようになりました。

: ((<String/strip>)) [compat]
: ((<String/strip!>)) [compat]
: ((<String/rstrip>)) [...

Regexp#=~(string) -> Integer | nil (212.0)

文字列 string との正規表現マッチを行います。マッチした場合、 マッチした位置のインデックスを返します(先頭は0)。マッチしなかった 場合、あるいは string が nil の場合には nil を返 します。

...文字列 string との正規表現マッチを行います。マッチした場合、
マッチした位置のインデックスを返します(先頭は0)。マッチしなかった
場合、あるいは string が nil の場合には nil を返
します。

//emlist[例][ruby]{
p /foo/ =~ "foo"...
...# => nil
//}

組み込み変数 $~ もしくは Regexp.last_match にマッチに関する情報 MatchData が設定されます。

文字列のかわりにSymbolをマッチさせることができます。

@param string マッチ対象文字列

@raise TypeError string が nil でも String オ...
...mlist[例][ruby]{
p /foo/ =~ "foo" # => 0
p Regexp.last_match(0) # => "foo"
p /foo/ =~ "afoo" # => 1
p $~[0] # => "foo"
p /foo/ =~ "bar" # => nil

unless /foo/ === "bar"
puts "not match " # => not match
end

str = []
begin
/ugo/ =~ str
rescue TypeError
prin...

Kernel$$~ -> MatchData | nil (122.0)

現在のスコープで最後に成功したマッチに関する MatchDataオブジェクトです。 Regexp.last_match の別名です。

...チに関する MatchDataオブジェクトです。
Regexp.last_match の別名です。

このデータから n 番目のマッチ ($n) を取り出すためには $~[n] を使います。

この値に代入すると Regexp.last_match や、 $&, $1, $2, ... などの関連する組み込み変...
...も nil でもない値を代入しようとすると TypeError が発生します。

この変数はローカルスコープかつスレッドローカルです。
Ruby起動時の初期値は nil です。

//emlist[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
i
f %r[<a...

Kernel$$1 -> String | nil (112.0)

最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。 該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)

...が格納されます。
該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)

番号 n はいくらでも大きな正整数を利用できます。

Regexp.last_match(1),
Regexp.last_match(2), ... と同じ。

これらの変数はローカルスコ...
...ープかつスレッドローカル、読み取り専用です。

//emlist[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
i
f %r[<a href="(.*?)">(.*?)</a>] =~ str
print $1
print $2
end
#=> "http://example.com"
#=> "example.com"
//}...

Kernel$$10 -> String | nil (112.0)

最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。 該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)

...が格納されます。
該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)

番号 n はいくらでも大きな正整数を利用できます。

Regexp.last_match(1),
Regexp.last_match(2), ... と同じ。

これらの変数はローカルスコ...
...ープかつスレッドローカル、読み取り専用です。

//emlist[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
i
f %r[<a href="(.*?)">(.*?)</a>] =~ str
print $1
print $2
end
#=> "http://example.com"
#=> "example.com"
//}...

絞り込み条件を変える

<< 1 2 3 > >>