30件ヒット
[1-30件を表示]
(0.030秒)
ライブラリ
- ビルトイン (30)
キーワード
-
fixed
_ encoding? (11) - match? (8)
- ~ (11)
検索結果
-
Regexp
# ~ -> Integer | nil (115.0) -
変数 $_ の値との間でのマッチをとります。
...> 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 は nil でも false でも無いので常にtrue
//}... -
Regexp
# match?(str , pos = 0) -> bool (36.0) -
指定された文字列 str に対して 位置 pos から自身が表す正規表現によるマッチングを行います。 マッチした場合 true を返し、マッチしない場合には false を返します。 また、$~ などパターンマッチに関する組み込み変数の値は変更されません。
...は false を返します。
また、$~ などパターンマッチに関する組み込み変数の値は変更されません。
//emlist[例][ruby]{
/R.../.match?("Ruby") # => true
/R.../.match?("Ruby", 1) # => false
/P.../.match?("Ruby") # => false
$& # => nil
//}......@see Regexp#match... -
Regexp
# fixed _ encoding? -> bool (30.0) -
正規表現が任意の ASCII 互換エンコーディングとマッチ可能な時に false を返します。
...現が任意の ASCII 互換エンコーディングとマッチ可能な時に false を返します。
//emlist[例][ruby]{
# -*- coding:utf-8 -*-
r = /a/
r.fixed_encoding? # => false
r.encoding # => #<Encoding:US-ASCII>
r =~ "\u......# => #<Encoding:UTF-8>
r =~ "\u{6666} a" # => 0
begin
r =~ "\xa1\xa2".force_encoding("euc-jp")
rescue => e
e.class # => Encoding::CompatibilityError
end
r =~ "abc".force_encoding("euc-jp") # => nil
//}...