るりまサーチ

最速Rubyリファレンスマニュアル検索!
58件ヒット [1-58件を表示] (0.005秒)
トップページ > クラス:Regexp[x] > 種類:インスタンスメソッド[x]

ライブラリ

キーワード

検索結果

Regexp#&(other) -> RedAnd (2)

RegAnd.new(self, other) を返します。

RegAnd.new(self, other) を返します。

@param other 正規表現オブジェクト。

Regexp#==(other) -> bool (2)

otherが同じパターン、オプション、文字コードの正規表現であったらtrueを返します。

...規表現であったらtrueを返します。

@param other 正規表現を指定します。

p /^eee$/ == /~eee$/x #=> false
p /^eee$/ == /~eee$/i #=> false
p /^eee$/e == /~eee$/u #=> false
p /^eee$/ == Regexp.new("^eee$") #=> true
p /^eee$/.eql?(/^eee$/) #=> true...

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#=~(string) -> Fixnum | nil (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#casefold? -> bool (2)

正規表現が大文字小文字の判定をしないようにコンパイルされている時、 真を返します。

...小文字の判定をしないようにコンパイルされている時、
真を返します。

reg = Regexp.new("foobar", Regexp::IGNORECASE)
p reg.casefold? #=> true

reg = Regexp.new("hogehoge")
p reg.casefold? #=> false...

絞り込み条件を変える

Regexp#encoding -> Encoding (2)

正規表現オブジェクトのエンコーディングを表す Encoding オブジェクト を返します。

正規表現オブジェクトのエンコーディングを表す Encoding オブジェクト
を返します。

Regexp#eql?(other) -> bool (2)

otherが同じパターン、オプション、文字コードの正規表現であったらtrueを返します。

...規表現であったらtrueを返します。

@param other 正規表現を指定します。

p /^eee$/ == /~eee$/x #=> false
p /^eee$/ == /~eee$/i #=> false
p /^eee$/e == /~eee$/u #=> false
p /^eee$/ == Regexp.new("^eee$") #=> true
p /^eee$/.eql?(/^eee$/) #=> true...

Regexp#fixed_encoding? -> bool (2)

正規表現が任意の ASCII 互換エンコーディングとマッチ可能な時に false を返します。

正規表現が任意の ASCII 互換エンコーディングとマッチ可能な時に false を返します。

Regexp#hash -> Fixnum (2)

正規表現のオプションやテキストに基づいたハッシュ値を返します。

正規表現のオプションやテキストに基づいたハッシュ値を返します。

p /abc/i.hash #=> 4893115
p /abc/.hash #=> 4856055

Regexp#inspect -> String (2)

Regexp#to_s より自然な文字列を返します。

...Regexp#to_s より自然な文字列を返します。

p /^ugou.*?/i.to_s #=> "(?i-mx:^ugou.*?)"
p /^ugou.*?/i.inspect #=> "/^ugou.*?/i"

@see Regexp#to_s...

絞り込み条件を変える

Regexp#kcode -> String | nil (2)

その正規表現が対応するようにコンパイルされている文字コードを $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 (2)

指定された文字列 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 (2)

指定された文字列 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#named_captures -> { String => [Integer] } (2)

正規表現に含まれる名前付きキャプチャ(named capture)の情報を Hash で返します。

正規表現に含まれる名前付きキャプチャ(named capture)の情報を
Hash で返します。

Hash のキーは名前付きキャプチャの名前で、値は
その名前に関連付けられたキャプチャの index のリストを返します。

/(?<foo>.)(?<bar>.)/.named_captures
#=> {"foo"=>[1], "bar"=>[2]}

/(?<foo>.)(?<foo>.)/.named_captures
#=> {"foo"=>[1, 2]}

# 名前付きキャプチャを持たないときは空の Hash を返します。
/(.)(.)/.named_...

Regexp#names -> [String] (2)

正規表現に含まれる名前付きキャプチャ(named capture)の名前を 文字列の配列で返します。

正規表現に含まれる名前付きキャプチャ(named capture)の名前を
文字列の配列で返します。

/(?<foo>.)(?<bar>.)(?<baz>.)/.names

#=> ["foo", "bar", "baz"]
/(?<foo>.)(?<foo>.)/.names
#=> ["foo"]

/(.)(.)/.names
#=> []

絞り込み条件を変える

Regexp#options -> Integer (2)

正規表現の生成時に指定されたオプションを返します。戻り値は、 Regexp::EXTENDED, Regexp::IGNORECASE, Regexp::MULTILINE, の論理和です。

...は、
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::IGNOREC...
...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 (2)

その正規表現のもととなった文字列表現を生成して返します。

その正規表現のもととなった文字列表現を生成して返します。

re = /foo|bar|baz/i
p re.source # => "foo|bar|baz"

Regexp#taguri -> String (2)

自身のタグ URI を返します。

自身のタグ URI を返します。

Regexp#taguri=(val) (2)

自身のタグ URI を val に設定します。

自身のタグ URI を val に設定します。

@param val タグ URI を文字列で指定します。

Regexp#to_json(*args) -> String (2)

自身を JSON 形式の文字列に変換して返します。

自身を JSON 形式の文字列に変換して返します。

内部的にはハッシュにデータをセットしてから Hash#to_json を呼び出しています。

@param args 引数には何の意味もありません。

絞り込み条件を変える

Regexp#to_s -> String (2)

正規表現の文字列表現を生成して返します。返される文字列は他の正規表 現に埋め込んでもその意味が保持されるようになっています。

...きないためです。

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#to_yaml(opts = {}) (2)

自身を 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#|(other) -> RegOr (2)

RegOr.new(self, other) を返します。

RegOr.new(self, other) を返します。

@param other 正規表現オブジェクト。

Regexp#~ -> Fixnum | nil (2)

変数 $_ の値との間でのマッチをとります。ちょうど以下と同じ意 味です。

...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...