種類
- インスタンスメソッド (206)
- 特異メソッド (99)
- 定数 (55)
ライブラリ
- ビルトイン (338)
-
json
/ add / regexp (22)
キーワード
- == (11)
- === (11)
- =~ (11)
- EXTENDED (11)
- FIXEDENCODING (11)
- IGNORECASE (11)
- MULTILINE (11)
- NOENCODING (11)
- casefold? (11)
- compile (11)
- encoding (11)
- eql? (11)
- escape (11)
-
fixed
_ encoding? (11) - hash (11)
- inspect (11)
-
json
_ create (11) -
last
_ match (22) - match (22)
- match? (8)
-
named
_ captures (11) - names (11)
- new (11)
- quote (11)
- source (11)
-
to
_ json (11) -
to
_ s (11) -
try
_ convert (11) - union (11)
- ~ (11)
検索結果
先頭5件
-
Regexp
# options -> Integer (101.0) -
正規表現の生成時に指定されたオプションを返します。戻り値は、 Regexp::EXTENDED, Regexp::IGNORECASE, Regexp::MULTILINE, Regexp::FIXEDENCODING, Regexp::NOENCODING, の論理和です。
...正規表現の生成時に指定されたオプションを返します。戻り値は、
Regexp::EXTENDED, Regexp::IGNORECASE,
Regexp::MULTILINE,
Regexp::FIXEDENCODING,
Regexp::NOENCODING,
の論理和です。
これで得られるオプションには生成時に指定したもの以外の
オ......Regexp.new にこれらを
渡しても無視されます。
//emlist[例][ruby]{
p Regexp::IGNORECASE # => 1
p //i.options # => 1
p Regexp.new("foo", Regexp::IGNORECASE ).options # => 1
p Regexp.new("foo", Regexp::EXTENDED).options # => 2
p Regexp.new("foo", Regexp::IGNORECASE | Regexp:......options # => 3
p Regexp.new("foo", Regexp::MULTILINE).options # => 4
p Regexp.new("foo", Regexp::IGNORECASE | Regexp::MULTILINE ).options # => 5
p Regexp.new("foo", Regexp::MULTILINE | Regexp::EXTENDED).options # =>6
p Regexp.new("foo", Regexp::IGNORECASE | Regexp::MULTILINE | Regexp::EXTENDED).opti... -
Regexp
# source -> String (101.0) -
その正規表現のもととなった文字列表現を生成して返します。
その正規表現のもととなった文字列表現を生成して返します。
//emlist[例][ruby]{
re = /foo|bar|baz/i
p re.source # => "foo|bar|baz"
//} -
Regexp
# to _ json(*args) -> String (101.0) -
自身を JSON 形式の文字列に変換して返します。
...enerator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数には何の意味もありません。
//emlist[例][ruby]{
require "json/add/core"
/0\d{1,4}-\d{1,4}-\d{4}/.to_json # => "{\"json_class\":\"Regexp\",\"o\":0,\"s\":\"0\\\\d{1,4}-\\\\d{1,4}-\\\\d{4}\"}"
//}......います。
@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json
に渡されます。
//emlist[例][ruby]{
require "json/add/core"
/0\d{1,4}-\d{1,4}-\d{4}/.to_json # => "{\"json_class\":\"Regexp\",\"o\":0,\"s\":\"0\\\\d{1,4}-\\\\d{1,4}-\\\\d{4}\"}"
//}... -
Regexp
# ~ -> Integer | nil (101.0) -
変数 $_ の値との間でのマッチをとります。
...hoge"
if /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... -
Regexp
. escape(string) -> String (101.0) -
string の中で正規表現において特別な意味を持つ文字の直前にエ スケープ文字(バックスラッシュ)を挿入した文字列を返します。
...持つ文字の直前にエ
スケープ文字(バックスラッシュ)を挿入した文字列を返します。
@param string 正規表現において特別な意味をもつ文字をもつ文字列を指定します。
//emlist[例][ruby]{
rp = Regexp.escape("$bc^")
p rp # => "\\$bc\\^"
//}... -
Regexp
. json _ create(hash) -> Regexp (101.0) -
JSON のオブジェクトから Ruby のオブジェクトを生成して返します。
JSON のオブジェクトから Ruby のオブジェクトを生成して返します。
@param hash 適切なキーを持つハッシュを指定します。 -
Regexp
. last _ match -> MatchData (101.0) -
カレントスコープで最後に行った正規表現マッチの 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 (101.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 は......を返します。
//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 整数を指... -
Regexp
. quote(string) -> String (101.0) -
string の中で正規表現において特別な意味を持つ文字の直前にエ スケープ文字(バックスラッシュ)を挿入した文字列を返します。
...持つ文字の直前にエ
スケープ文字(バックスラッシュ)を挿入した文字列を返します。
@param string 正規表現において特別な意味をもつ文字をもつ文字列を指定します。
//emlist[例][ruby]{
rp = Regexp.escape("$bc^")
p rp # => "\\$bc\\^"
//}... -
Regexp
. try _ convert(obj) -> Regexp | nil (101.0) -
obj を to_regexp メソッドで Regexp オブジェクトに変換しようと 試みます。
...obj を to_regexp メソッドで Regexp オブジェクトに変換しようと
試みます。
変換に成功した場合はそれを返し、失敗時には nil を返します。
//emlist[例][ruby]{
Regexp.try_convert(/re/) # => /re/
Regexp.try_convert("re") # => nil
//}...