種類
- 変数 (22)
- 特異メソッド (22)
- インスタンスメソッド (11)
- 文書 (11)
クラス
- Regexp (33)
モジュール
- Kernel (22)
キーワード
-
$ LAST _ MATCH _ INFO (11) -
$ ~ (11) -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - =~ (11)
検索結果
先頭5件
-
Regexp
. last _ match -> MatchData (18268.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
//}... -
Regexp
. last _ match(nth) -> String | nil (18188.0) -
整数 nth が 0 の場合、マッチした文字列を返します ($&)。それ以外では、nth 番目の括弧にマッチ した部分文字列を返します($1,$2,...)。 対応する括弧がない場合やマッチしなかった場合には nil を返し ます。
..."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) は 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... -
Kernel
$ $ LAST _ MATCH _ INFO -> MatchData | nil (6226.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... -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (912.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への変更点(まとめ)/サポートプラットフォームの追加>))
...よくわかりません(^^;
class << Object
p [self.id, self]
class << self
p [self.id, self]
end
end
=> ruby 1.6.7 (2002-03-01) [i586-linux]
[537771634, Class]
[537742484, Class]
=> ruby 1.7.3 (2002-09......Marshal/Object#marshal_dump>)) [new]
追加 ((<ruby-dev:21016>))
=== MatchData
: ((<MatchData#captures|MatchData/captures>)) [new]
追加。((<RCR#139>))
: ((<MatchData#select|MatchData/select>)) [new]
((<MatchData>)) は、Enumerable ではありませんが、Enumerable#select
と......。((<ruby-dev:17968>))
=== Regexp
: ((<Regexp#===|Regexp/===>)) [compat]
真偽値を返すようになりました。
: ((<Regexp/Regexp.last_match>)) [compat]
optional な引数が追加されました。
=== String
: ((<String/String.new>)) [compat]
String.new の引数を... -
Kernel
$ $ ~ -> MatchData | nil (151.0) -
現在のスコープで最後に成功したマッチに関する MatchDataオブジェクトです。 Regexp.last_match の別名です。
...後に成功したマッチに関する MatchDataオブジェクトです。
Regexp.last_match の別名です。
このデータから n 番目のマッチ ($n) を取り出すためには $~[n] を使います。
この値に代入すると Regexp.last_match や、 $&, $1, $2, ... などの関......連する組み込み変数の値が変化します。
MatchData オブジェクトでも nil でもない値を代入しようとすると TypeError が発生します。
この変数はローカルスコープかつスレッドローカルです。
Ruby起動時の初期値は nil です。
//em......list[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
if %r[<a href="(.*?)">(.*?)</a>] =~ str
p $~[1]
end
#=> "http://example.com"
//}... -
Regexp
# =~(string) -> Integer | nil (30.0) -
文字列 string との正規表現マッチを行います。マッチした場合、 マッチした位置のインデックスを返します(先頭は0)。マッチしなかった 場合、あるいは string が nil の場合には nil を返 します。
...p /foo/ =~ "foo" # => 0
p /foo/ =~ "afoo" # => 1
p /foo/ =~ "bar" # => nil
//}
組み込み変数 $~ もしくは Regexp.last_match にマッチに関する情報 MatchData が設定されます。
文字列のかわりにSymbolをマッチさせることができます。
@param string マッ......list[例][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
print......f "! %s\t%s\n", $!, $@ # => ! can't convert Array into String r5.rb:15
end
//}...