るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.190秒)
トップページ > クエリ:-[x] > クエリ:E[x] > クエリ:Ruby[x] > クエリ:printf[x] > クラス:Regexp[x]

別のキーワード

  1. open3 popen2e
  2. socket af_e164
  3. matrix rank_e
  4. matrix det_e
  5. open3 capture2e

ライブラリ

検索結果

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

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

...合、あるいは string が nil の場合には nil を返
します。

//emlist[例][ruby]{
p /foo/ =~ "foo" # => 0
p /foo/ =~ "afoo" # => 1
p /foo/ =~ "bar" # => nil
//}

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

@param string マッチ対象文字列

@raise TypeError string が nil でも String オブジェクト
でも Symbol でもない場合発生します。

//emlist[例][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
e
nd

str = []
begin
/ugo/ =~ str
rescue TypeError
printf
"! %s\t%s\n", $!, $@ # => ! can't convert Array into String r5.rb:15
e
nd
//}...