るりまサーチ

最速Rubyリファレンスマニュアル検索!
2396件ヒット [1-100件を表示] (0.114秒)
トップページ > クエリ:p[x] > クエリ:Regexp[x]

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. kernel p
  5. rsa p

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Regexp (44090.0)

正規表現のクラス。正規表現のリテラルはスラッシュで囲んだ形式 で記述します。

...is regexp/
//}

Regexp
.new(string) を使って正規表現オブジェクトを動的に生成する
こともできます。

//emlist[][ruby]{
str = "this is regexp"
rp1 = Regexp.new("^this is regexp")
p
rp1 =~ str # => 0
p
Regexp.last_match[0] # => "this is regexp"
//}


spec/regexp...
...や d:spec/literal#regexp も参照してください。...
...]{
/^this is regexp/
//}

Regexp
.new(string) を使って正規表現オブジェクトを動的に生成する
こともできます。

//emlist[][ruby]{
str = "this is regexp"
rp1 = Regexp.new("^this is regexp")
p
rp1 =~ str # => 0
p
Regexp.last_match[0] # => "this is regexp"
//}

Ruby...
...3.0.0 から正規表現リテラルは freeze されるようになりました。
//emlist[][ruby]{
p
/abc/.frozen?
# => true
p
/a#{42}bc/.frozen?
# => true
p
Regexp.new('abc').frozen?
# => false
//}

spec/regexp や d:spec/literal#regexp も参照してください。...

Regexp#options -> Integer (27360.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).opt...

Regexp.compile(string, option = nil) -> Regexp (27322.0)

文字列 string をコンパイルして正規表現オブジェクトを生成して返します。

...を複製して返します。第二引数は警告の上無視されます。

@param string 正規表現を文字列として与えます。

@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp
::EXTENDED
の論理和を指定します。
Integer...
...あれば
Regexp
::IGNORECASE の指定と同じになります。

@raise RegexpError 正規表現のコンパイルに失敗した場合発生します。

//emlist[例][ruby]{
str = "This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
p
$~ # => "T...
...exp"

t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp # ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
p
Regexp.last_match # => "This is Regexp"

str = "ふるいけや\nかわずとびこむ\nみずのおと"
t2 = Regexp.compil...

Regexp.compile(string, option = nil, code = nil) -> Regexp (27322.0)

文字列 string をコンパイルして正規表現オブジェクトを生成して返します。

...して返します。第二、第三引数は警告の上無視されます。

@param string 正規表現を文字列として与えます。

@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp
::EXTENDED
の論理和を指定します。
Integer...
...
Regexp
::IGNORECASE の指定と同じになります。

@param code "n", "N" が与えられた時には、生成された正規表現のエンコーディングは ASCII-8BIT になります。
それ以外の指定は警告を出力します。

@raise RegexpError...
...This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
p
$~ # => "This is Regexp"

t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp # ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
p
Regexp.last_m...

Regexp#inspect -> String (27134.0)

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

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

//emlist[例][ruby]{
p
/^ugou.*?/i.to_s # => "(?i-mx:^ugou.*?)"
p
/^ugou.*?/i.inspect # => "/^ugou.*?/i"
//}

@see Regexp#to_s...

絞り込み条件を変える

Regexp.escape(string) -> String (27112.0)

string の中で正規表現において特別な意味を持つ文字の直前にエ スケープ文字(バックスラッシュ)を挿入した文字列を返します。

...持つ文字の直前にエ
スケープ文字(バックスラッシュ)を挿入した文字列を返します。

@param string 正規表現において特別な意味をもつ文字をもつ文字列を指定します。

//emlist[例][ruby]{
rp = Regexp.escape("$bc^")
p
rp # => "\\$bc\\^"
//}...

Regexp#named_captures -> { String => [Integer] } (27100.0)

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

...ャプチャ(named capture)の情報を
Hash で返します。

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

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

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

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

Regexp.union(*pattern) -> Regexp (24467.0)

引数として与えた pattern を選択 | で連結し、Regexp として返します。 結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。

...引数として与えた pattern を選択 | で連結し、Regexp として返します。
結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。

//emlist[][ruby]{
p
Regexp.union(/a/, /b/, /c/) # => /(?-mix:a)|(?-mix:b)|(?-mix:c)/
//}...
...ay を与えても Regexp を生成します。
つまり、以下のように書くことができます。

//emlist[][ruby]{
arr = [/a/, /b/, /c/]
p
Regexp.union(arr) # => /(?-mix:a)|(?-mix:b)|(?-mix:c)/
# 1.8.7 より前は、以下のように書く必要があった
p
Regexp.union(*arr) # =>...
...//}

p
attern は Regexp または String で与えます。
String で与えた場合、それ自身と等しい文字列にマッチするものと解釈され、
エスケープされて結果の Regexp に組み込まれます。

//emlist[][ruby]{
p
Regexp.union("a", "?", "b") # => /a|\?|b/
p
Re...

Regexp.new(string, option = nil) -> Regexp (24322.0)

文字列 string をコンパイルして正規表現オブジェクトを生成して返します。

...を複製して返します。第二引数は警告の上無視されます。

@param string 正規表現を文字列として与えます。

@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp
::EXTENDED
の論理和を指定します。
Integer...
...あれば
Regexp
::IGNORECASE の指定と同じになります。

@raise RegexpError 正規表現のコンパイルに失敗した場合発生します。

//emlist[例][ruby]{
str = "This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
p
$~ # => "T...
...exp"

t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp # ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
p
Regexp.last_match # => "This is Regexp"

str = "ふるいけや\nかわずとびこむ\nみずのおと"
t2 = Regexp.compil...

Regexp.new(string, option = nil, code = nil) -> Regexp (24322.0)

文字列 string をコンパイルして正規表現オブジェクトを生成して返します。

...して返します。第二、第三引数は警告の上無視されます。

@param string 正規表現を文字列として与えます。

@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp
::EXTENDED
の論理和を指定します。
Integer...
...
Regexp
::IGNORECASE の指定と同じになります。

@param code "n", "N" が与えられた時には、生成された正規表現のエンコーディングは ASCII-8BIT になります。
それ以外の指定は警告を出力します。

@raise RegexpError...
...This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
p
$~ # => "This is Regexp"

t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp # ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
p
Regexp.last_m...

絞り込み条件を変える

Regexp.try_convert(obj) -> Regexp | nil (24245.0)

obj を to_regexp メソッドで Regexp オブジェクトに変換しようと 試みます。

...obj を to_regexp メソッドで Regexp オブジェクトに変換しようと
試みます。

変換に成功した場合はそれを返し、失敗時には nil を返します。

//emlist[例][ruby]{
Regexp
.try_convert(/re/) # => /re/
Regexp
.try_convert("re") # => nil
//}...
<< 1 2 3 ... > >>