るりまサーチ

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

キーワード

検索結果

<< 1 2 3 ... > >>

Regexp#==(other) -> bool (3.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$/) # => true
//}...

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

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

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

string が文字列でもシンボルでもない場合には false を返します。

このメソッドは主にcase文での比較に用いられます。

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

Regexp#=~(string) -> Integer | nil (3.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#casefold? -> bool (3.0)

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

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

//emlist[例][ruby]{
reg = Regexp.new("foobar", Regexp::IGNORECASE)
p reg.casefold? # => true

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

Regexp#encoding -> Encoding (3.0)

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

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


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

絞り込み条件を変える

Regexp#eql?(other) -> bool (3.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$/) # => true
//}...

Regexp#fixed_encoding? -> bool (3.0)

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

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

//emlist[例][ruby]{
# -*- coding:utf-8 -*-

r = /a/
r.fixed_encoding? # => false
r.encoding # => #<Encoding:US-ASCII>
r =~ "\u{6666} a" # => 2
r =~ "\xa1\...

Regexp#hash -> Integer (3.0)

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

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

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

Regexp#inspect -> String (3.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#match(str, pos = 0) -> MatchData | nil (3.0)

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

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

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

if reg.match("foobar")
puts "match"
end
# => match

p reg.match("foobar") # => #<MatchData:0x29403fc>
p reg.match("bar") # => nil...
...に失敗した場合、
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?...

絞り込み条件を変える

<< 1 2 3 ... > >>