種類
- インスタンスメソッド (26)
- 特異メソッド (17)
ライブラリ
- ビルトイン (39)
- eregex (1)
-
syck
/ rubytypes (2) -
yaml
/ rubytypes (1)
検索結果
先頭5件
-
Regexp
# |(other) -> RegOr (18101) -
RegOr.new(self, other) を返します。
RegOr.new(self, other) を返します。
@param other 正規表現オブジェクト。 -
Regexp
# =~(string) -> Fixnum | nil (102) -
文字列 string との正規表現マッチを行います。マッチした場合、 マッチした位置のインデックスを返します(先頭は0)。マッチしなかった 場合、あるいは string が nil の場合には nil を返 します。
...~ "bar" #=> nil
組み込み変数 $~ もしくは Regexp.last_match にマッチに関する情報 MatchData が設定されます。
string がnil でも String オブジェクトでもなけれ
ば例外 TypeError が発生します。
Regexp#=== は、真偽値を返します。引数が文......TypeError string がnil でも String オブジェクトでもない
場合発生します。
p /foo/ =~ "foo" #=> 0
p Regexp.last_match(0) #=> "foo"
p /foo/ =~ "afoo" #=> 1
p $~[0] #=> "foo"
p /foo/ =~ "bar" #=> nil
unless /foo/ ==... -
Regexp
# kcode -> String | nil (102) -
その正規表現が対応するようにコンパイルされている文字コードを $KCODE と同じ形式で返します。もし、正規表現が固定 コードに対してコンパイルされていない(マッチ時点での $KCODE の値を用いる)場合には、nil を返します。
...し、正規表現が固定
コードに対してコンパイルされていない(マッチ時点での $KCODE
の値を用いる)場合には、nil を返します。
reg = Regexp.new("hogehoge", nil, "u")
p reg.kcode #=> "utf8"
reg = Regexp.new("hogehoge", nil)
p reg.kcode #=> "nil"... -
Regexp
# match(str) -> MatchData | nil (102) -
指定された文字列 str に対して 自身が表す正規表現によるマッチングを行います。マッチした場合には結果を MatchData オブジェクトで返します。 マッチしなかった場合 nil を返します。
...た場合 nil を返します。
@param str 文字列を指定します。str との正規表現マッチを行います。
使用例
reg = Regexp.new("foo")
if reg.match("foobar")
print "match\n" #=> match
end
p reg.match("foobar") #=> #<MatchData:0x29403fc>
p reg.match("bar")... -
Regexp
# match(str , pos = 0) -> MatchData | nil (102) -
指定された文字列 str に対して 位置 pos から 自身が表す正規表現によるマッチングを行います。マッチした場合には結果を MatchData オブジェクトで返します。 マッチしなかった場合 nil を返します。
...数を指定します。マッチの開始位置を pos から行うよう制御できます(pos のデフォルト値は 0)。
使用例
reg = Regexp.new("foo")
if reg.match("foobar")
print "match\n" #=> match
end
p reg.match("foobar") #=> #<MatchData:0x29403fc>
p reg.match("bar")... -
Regexp
# ~ -> Fixnum | nil (102) -
変数 $_ の値との間でのマッチをとります。ちょうど以下と同じ意 味です。
...oo/
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 ma... -
Regexp
. last _ match(nth) -> String | nil (102) -
整数 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......(1) は nil を返します。
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
. try _ convert(obj) -> Regexp | nil (102) -
obj を to_regexp メソッドで Regexp オブジェクトに変換しようと 試みます。
...obj を to_regexp メソッドで Regexp オブジェクトに変換しようと
試みます。
変換に成功した場合はそれを返し、失敗時には nil を返します。
Regexp.try_convert(/re/) # => /re/
Regexp.try_convert("re") # => nil... -
Regexp
# to _ s -> String (85) -
正規表現の文字列表現を生成して返します。返される文字列は他の正規表 現に埋め込んでもその意味が保持されるようになっています。
...表
現に埋め込んでもその意味が保持されるようになっています。
re = /foo|bar|baz/i
p re.to_s # => "(?i-mx:foo|bar|baz)"
p /#{re}+/o # => /(?i-mx:foo|bar|baz)+/
ただし、後方参照を含む正規表現は意図通りにはならない場合がありま......きないためです。
re = /(foo|bar)\1/ # \1 は、foo か bar
p /(baz)#{re}/ # \1 は、baz
# => /(baz)(?-mix:(foo|bar)\1)/
使用例
re = /foo|bar|baz/i
p re.to_s # => "(?i-mx:foo|bar|baz)"
p /#{re}+/o # => /(?i-mx:foo|bar|baz)+/
@see Regexp#inspect... -
Regexp
. union(*pattern) -> Regexp (59) -
引数として与えた pattern を選択 | で連結し、Regexp として返します。 結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。
...として与えた pattern を選択 | で連結し、Regexp として返します。
結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。
p Regexp.union(/a/, /b/, /c/) #=> /(?-mix:a)|(?-mix:b)|(?-mix:c)/
引数を一つだけ与え......も Regexp を生成します。
つまり、以下のように書くことができます。
arr = [/a/, /b/, /c/]
p Regexp.union(arr) #=> /(?-mix:a)|(?-mix:b)|(?-mix:c)/
# 1.8.7 より前は、以下のように書く必要があった
p Regexp.union(*arr) #=> /(?-mix:a)|(?-mix:b)|(?-mix......pattern は Regexp または String で与えます。
String で与えた場合、それ自身と等しい文字列にマッチするものと解釈され、
エスケープされて結果の Regexp に組み込まれます。
p Regexp.union("a", "?", "b") # => /a|\?|b/
p Regexp.union(/a/, "... -
Regexp
# options -> Integer (31) -
正規表現の生成時に指定されたオプションを返します。戻り値は、 Regexp::EXTENDED, Regexp::IGNORECASE, Regexp::MULTILINE, Regexp::FIXEDENCODING, Regexp::NOENCODING, の論理和です。
...
Regexp::EXTENDED, Regexp::IGNORECASE,
Regexp::MULTILINE,
の論理和です。
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 |......tions #=> 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).op......正規表現の生成時に指定されたオプションを返します。戻り値は、
Regexp::EXTENDED, Regexp::IGNORECASE,
Regexp::MULTILINE,
Regexp::FIXEDENCODING,
の論理和です。
これで得られるオプションには生成時に指定したもの以外の
オプションを含......で、Regexp.new にこれらを
渡しても無視されます。
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::EXTEND......正規表現の生成時に指定されたオプションを返します。戻り値は、
Regexp::EXTENDED, Regexp::IGNORECASE,
Regexp::MULTILINE,
Regexp::FIXEDENCODING,
Regexp::NOENCODING,
の論理和です。
これで得られるオプションには生成時に指定したもの以外の
オ... -
Regexp
# source -> String (25) -
その正規表現のもととなった文字列表現を生成して返します。
...その正規表現のもととなった文字列表現を生成して返します。
re = /foo|bar|baz/i
p re.source # => "foo|bar|baz"... -
Regexp
# to _ yaml(opts = {}) (13) -
自身を YAML ドキュメントに変換します。
...L ドキュメントに変換します。
@param opts YAML ドキュメント出力の際のオプションを指定します。
オプションの詳細は YAML::Syck::Emitter#reset を参照し
てください。
print /foo|bar/.to_yaml # => --- !ruby/regexp /foo|bar/......YAML ドキュメントに変換します。
@param opts YAML ドキュメント出力の際のオプションを指定します。
オプションの詳細は Syck::Emitter#reset を参照し
てください。
print /foo|bar/.to_yaml # => --- !ruby/regexp /foo|bar/... -
Regexp
. compile(string , option = nil , code = nil) -> Regexp (7) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp::EXTENDED
の論理和を指定します。
Fixnum 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp::IGNORECASE...... RegexpError 正規表現のコンパイルに失敗した場合発生します。
str = "This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
puts $~ #=> This is Regexp
t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp......# ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
puts Regexp.last_match #=> This is Regexp
str = "ふるいけや\nかわずとびこむ\nみずのおと"
t2 = Regexp.compile("ふる.*?と", Regexp::MULTILINE)
puts t2.match(str)[0] #=> ふる... -
Regexp
. new(string , option = nil , code = nil) -> Regexp (7) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp::EXTENDED
の論理和を指定します。
Fixnum 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp::IGNORECASE...... RegexpError 正規表現のコンパイルに失敗した場合発生します。
str = "This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
puts $~ #=> This is Regexp
t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp......# ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
puts Regexp.last_match #=> This is Regexp
str = "ふるいけや\nかわずとびこむ\nみずのおと"
t2 = Regexp.compile("ふる.*?と", Regexp::MULTILINE)
puts t2.match(str)[0] #=> ふる... -
Regexp
# ===(string) -> bool (2) -
文字列 string との正規表現マッチを行います。マッチした場合、 マッチした位置のインデックスを返します(先頭は0)。マッチしなかった 場合、あるいは string が nil の場合には nil を返 します。
...~ "bar" #=> nil
組み込み変数 $~ もしくは Regexp.last_match にマッチに関する情報 MatchData が設定されます。
string がnil でも String オブジェクトでもなけれ
ば例外 TypeError が発生します。
Regexp#=== は、真偽値を返します。引数が文......TypeError string がnil でも String オブジェクトでもない
場合発生します。
p /foo/ =~ "foo" #=> 0
p Regexp.last_match(0) #=> "foo"
p /foo/ =~ "afoo" #=> 1
p $~[0] #=> "foo"
p /foo/ =~ "bar" #=> nil
unless /foo/ ==... -
Regexp
. last _ match -> MatchData (2) -
カレントスコープで最後に行った正規表現マッチの MatchData オ ブジェクトを返します。このメソッドの呼び出しは $~ の参照と同じです。
...ます。このメソッドの呼び出しは $~
の参照と同じです。
/(.)(.)/ =~ "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...
