るりまサーチ

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

ライブラリ

キーワード

検索結果

<< 1 2 3 > >>

Regexp.compile(string, option = nil, code = nil) -> Regexp (25.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.new(string, option = nil, code = nil) -> Regexp (25.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#match(str, pos = 0) -> MatchData | nil (19.0)

指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。

...# => ["oo"]
//}

@
param str 文字列を指定します。str との正規表現マッチを行います。

@
param pos 整数を指定します。マッチの開始位置を pos から行うよう制御できます(pos のデフォルト値は 0)。

//emlist[例][ruby]{
reg = Regexp.new("foo")

if...
...に失敗した場合、
nil.captures を呼び出そうとして例外 NoMethodError が発生して
しまいます。

//emlist[例][ruby]{
foo, bar, baz = /(foo)(bar)(baz)/.match("foobar").captures

# => -:1: undefined method `captures' for nil:NilClass (NoMethodError)
//}

@
see Regexp#match?...

Regexp#match(str, pos = 0) {|m| ... } -> object | nil (19.0)

指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。

...# => ["oo"]
//}

@
param str 文字列を指定します。str との正規表現マッチを行います。

@
param pos 整数を指定します。マッチの開始位置を pos から行うよう制御できます(pos のデフォルト値は 0)。

//emlist[例][ruby]{
reg = Regexp.new("foo")

if...
...に失敗した場合、
nil.captures を呼び出そうとして例外 NoMethodError が発生して
しまいます。

//emlist[例][ruby]{
foo, bar, baz = /(foo)(bar)(baz)/.match("foobar").captures

# => -:1: undefined method `captures' for nil:NilClass (NoMethodError)
//}

@
see Regexp#match?...

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

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

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

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

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

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

//emlist[例][ruby]{
str = "This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(s...
...xp"

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

絞り込み条件を変える

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

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

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

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

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

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

//emlist[例][ruby]{
str = "This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(s...
...xp"

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

Regexp#===(string) -> bool (13.0)

文字列 string との正規表現マッチを行います。 マッチした場合は真を返します。

...

@
param string マッチ対象文字列

//emlist[例][ruby]{
a = "HELLO"
case a
when /\A[a-z]*\z/; puts "Lower case"
when /\A[A-Z]*\z/; puts "Upper case"
else; puts "Mixed case"
end
# => Upper case

/\A[a-z]*\z/ === "HELLO" # => false
/\A[A-Z]*\z/ === "HELLO" # => true
//}

@
see En...

Regexp#=~(string) -> Integer | nil (13.0)

文字列 string との正規表現マッチを行います。マッチした場合、 マッチした位置のインデックスを返します(先頭は0)。マッチしなかった 場合、あるいは string が nil の場合には nil を返 します。

...# => nil
//}

組み込み変数 $~ もしくは Regexp.last_match にマッチに関する情報 MatchData が設定されます。

文字列のかわりにSymbolをマッチさせることができます。

@
param string マッチ対象文字列

@
raise TypeError string が nil でも String オ...
...# => 0
p Regexp.last_match(0) # => "foo"
p /foo/ =~ "afoo" # => 1
p $~[0] # => "foo"
p /foo/ =~ "bar" # => nil

unless /foo/ === "bar"
puts "not match " # => not match
end

str = []
begin
/ugo/ =~ str
rescue TypeError
printf "! %s\t%s\n", $!, $@ # => ! can't...

Regexp#match(str, pos = 0) -> MatchData | nil (13.0)

指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。

...# => ["oo"]
//}

@
param str 文字列を指定します。str との正規表現マッチを行います。

@
param pos 整数を指定します。マッチの開始位置を pos から行うよう制御できます(pos のデフォルト値は 0)。

//emlist[例][ruby]{
reg = Regexp.new("foo")

if...

Regexp#match(str, pos = 0) {|m| ... } -> object | nil (13.0)

指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。

...# => ["oo"]
//}

@
param str 文字列を指定します。str との正規表現マッチを行います。

@
param pos 整数を指定します。マッチの開始位置を pos から行うよう制御できます(pos のデフォルト値は 0)。

//emlist[例][ruby]{
reg = Regexp.new("foo")

if...

絞り込み条件を変える

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

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

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

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

//emlist[例][ruby]{
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$/)...

Regexp#encoding -> Encoding (7.0)

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

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


@
see d:spec/regexp#encoding...

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

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

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

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

//emlist[例][ruby]{
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$/)...
<< 1 2 3 > >>