るりまサーチ (Ruby 2.7.0)

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

別のキーワード

  1. openssl integer
  2. asn1 integer
  3. _builtin integer
  4. integer chr
  5. integer new

ライブラリ

キーワード

検索結果

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

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

...す。

//emlist[例][ruby]{
p /foo/ =~ "foo" # => 0
p /foo/ =~ "afoo" # => 1
p /foo/ =~ "bar" # => nil
//}

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

文字列のかわりにSymbolをマッチさせることができま...
...tring オブジェクト
でも Symbol でもない場合発生します。

//emlist[例][ruby]{
p /foo/ =~ "foo" # => 0
p Regexp.last_match(0) # => "foo"
p /foo/ =~ "afoo" # => 1
p $~[0] # => "foo"
p /foo/ =~ "bar" # => nil

unless /foo/ === "b...

Regexp#hash -> Integer (307.0)

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

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

//emlist[例][ruby]{
p /abc/i.hash # => 4893115
p /abc/.hash # => 4856055
//}

Regexp#named_captures -> { String => [Integer] } (307.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 を返します。
/(.)(.)/...

Regexp#options -> Integer (307.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#~ -> Integer | nil (307.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::EXTENDED -> Integer (307.0)

バックスラッシュでエスケープされていない空白と # から改行までを無 視します。正規表現リテラルの //x オプションと同じ です。(空白を入れる場合は\でエスケープして\ (<-空白)と 指定します)

バックスラッシュでエスケープされていない空白と # から改行までを無
視します。正規表現リテラルの //x オプションと同じ
です。(空白を入れる場合は\でエスケープして\ (<-空白)と
指定します)

Regexp::FIXEDENCODING -> Integer (307.0)

正規表現が特定のエンコーディングの文字列にしかマッチしないことを意味します。

...正規表現が特定のエンコーディングの文字列にしかマッチしないことを意味します。

@see Regexp#fixed_encoding?...

Regexp::IGNORECASE -> Integer (307.0)

文字の大小の違いを無視します。 正規表現リテラルの //i オプションと同じです。

文字の大小の違いを無視します。
正規表現リテラルの //i オプションと同じです。

Regexp::MULTILINE -> Integer (307.0)

複数行モード。正規表現 "." が改行にマッチするようになります。 正規表現リテラルの //m オプションと同じです。

複数行モード。正規表現 "." が改行にマッチするようになります。
正規表現リテラルの //m オプションと同じです。

Regexp::NOENCODING -> Integer (307.0)

正規表現のマッチ時に文字列のエンコーディングを無視し、 バイト列としてマッチすることを意味します。

正規表現のマッチ時に文字列のエンコーディングを無視し、
バイト列としてマッチすることを意味します。

正規表現リテラルの n オプションに対応します。

絞り込み条件を変える

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

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

...@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp
::EXTENDED
の論理和を指定します。
Integer 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp
::IGNORECASE...
...を出力します。

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

//emlist[例][ruby]{
str = "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_match # => "This is Regexp"

str = "ふるいけや\nかわずとびこむ\nみずのおと"
t2 = Regexp.compile("ふる.*?と", Regexp::MULTILINE)
p t2.match(str)...

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

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

...@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp
::EXTENDED
の論理和を指定します。
Integer 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp
::IGNORECASE...
...を出力します。

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

//emlist[例][ruby]{
str = "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_match # => "This is Regexp"

str = "ふるいけや\nかわずとびこむ\nみずのおと"
t2 = Regexp.compile("ふる.*?と", Regexp::MULTILINE)
p t2.match(str)...