413件ヒット
[401-413件を表示]
(0.300秒)
ライブラリ
- ビルトイン (413)
キーワード
- == (11)
- =~ (11)
- [] (44)
- begin (11)
- byteoffset (4)
- captures (11)
- end (11)
- eql? (11)
- gsub (11)
- gsub! (11)
- hash (11)
- inspect (11)
- length (11)
- match? (24)
-
named
_ captures (11) - names (11)
- offset (22)
-
post
_ match (11) -
pre
_ match (11) - regexp (11)
- size (11)
- string (11)
- sub (11)
- sub! (11)
-
to
_ a (11) -
to
_ s (11) -
values
_ at (11) - ~ (11)
検索結果
-
Regexp
# ~ -> Integer | nil (8055.0) -
変数 $_ の値との間でのマッチをとります。
...foo/
puts "match"
else
puts "no match"
end
# => no match
# ただし、警告がでる。warning: regex literal in condition
reg = Regexp.compile("foo")
if ~ reg
puts "match"
else
puts "no match"
end
# => no match
if reg
puts "match"
else
puts "no match"
end
# => match
# reg は ni... -
Regexp
# =~(string) -> Integer | nil (8025.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 マッ......ist[例][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
printf...