種類
- インスタンスメソッド (18)
- 特異メソッド (9)
- 定数 (5)
ライブラリ
- ビルトイン (30)
-
json
/ add / regexp (2)
キーワード
- == (1)
- === (1)
- =~ (1)
- EXTENDED (1)
- FIXEDENCODING (1)
- IGNORECASE (1)
- MULTILINE (1)
- NOENCODING (1)
- casefold? (1)
- compile (1)
- encoding (1)
- eql? (1)
- escape (1)
-
fixed
_ encoding? (1) - hash (1)
- inspect (1)
-
json
_ create (1) -
last
_ match (2) - match (2)
-
named
_ captures (1) - names (1)
- new (1)
- quote (1)
- source (1)
-
to
_ json (1) -
to
_ s (1) -
try
_ convert (1) - union (1)
- ~ (1)
検索結果
先頭5件
-
Regexp
# ==(other) -> bool (2.0) -
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.0) -
文字列 string との正規表現マッチを行います。 マッチした場合は真を返します。
文字列 string との正規表現マッチを行います。
マッチした場合は真を返します。
string が文字列でもシンボルでもない場合には false を返します。
このメソッドは主にcase文での比較に用いられます。
@param string マッチ対象文字列
例:
a = "HELLO"
case a
when /\A[a-z]*\z/; print "Lower case\n"
when /\A[A-Z]*\z/; print "Upper case\n"
else; print "Mixed case\n"
end
# => "... -
Regexp
# =~(string) -> Integer | nil (2.0) -
文字列 string との正規表現マッチを行います。マッチした場合、 マッチした位置のインデックスを返します(先頭は0)。マッチしなかった 場合、あるいは string が nil の場合には nil を返 します。
...には nil を返
します。
p /foo/ =~ "foo" #=> 0
p /foo/ =~ "afoo" #=> 1
p /foo/ =~ "bar" #=> nil
組み込み変数 $~ もしくは Regexp.last_match にマッチに関する情報 MatchData が設定されます。
文字列のかわりにSymbolをマッチさせることができ......g が nil でも String オブジェクト
でも Symbol でもない場合発生します。
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.0) -
正規表現が大文字小文字の判定をしないようにコンパイルされている時、 真を返します。
...小文字の判定をしないようにコンパイルされている時、
真を返します。
reg = Regexp.new("foobar", Regexp::IGNORECASE)
p reg.casefold? #=> true
reg = Regexp.new("hogehoge")
p reg.casefold? #=> false... -
Regexp
# encoding -> Encoding (2.0) -
正規表現オブジェクトのエンコーディングを表す Encoding オブジェクト を返します。
...正規表現オブジェクトのエンコーディングを表す Encoding オブジェクト
を返します。
@see d:spec/regexp#encoding... -
Regexp
# eql?(other) -> bool (2.0) -
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.0) -
正規表現が任意の ASCII 互換エンコーディングとマッチ可能な時に false を返します。
正規表現が任意の ASCII 互換エンコーディングとマッチ可能な時に false を返します。
例:
# -*- coding:utf-8 -*-
r = /a/
r.fixed_encoding? # => false
r.encoding # => #<Encoding:US-ASCII>
r =~ "\u{6666} a" # => 2
r =~ "\xa1\xa2 ... -
Regexp
# hash -> Integer (2.0) -
正規表現のオプションやテキストに基づいたハッシュ値を返します。
正規表現のオプションやテキストに基づいたハッシュ値を返します。
p /abc/i.hash #=> 4893115
p /abc/.hash #=> 4856055 -
Regexp
# inspect -> String (2.0) -
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
# match(str , pos = 0) -> MatchData | nil (2.0) -
指定された文字列 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
# match(str , pos = 0) {|m| . . . } -> object | nil (2.0) -
指定された文字列 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.0) -
正規表現に含まれる名前付きキャプチャ(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.0) -
正規表現に含まれる名前付きキャプチャ(named capture)の名前を 文字列の配列で返します。
正規表現に含まれる名前付きキャプチャ(named capture)の名前を
文字列の配列で返します。
/(?<foo>.)(?<bar>.)(?<baz>.)/.names
#=> ["foo", "bar", "baz"]
/(?<foo>.)(?<foo>.)/.names
#=> ["foo"]
/(.)(.)/.names
#=> [] -
Regexp
# options -> Integer (2.0) -
正規表現の生成時に指定されたオプションを返します。戻り値は、 Regexp::EXTENDED, Regexp::IGNORECASE, Regexp::MULTILINE, Regexp::FIXEDENCODING, Regexp::NOENCODING, の論理和です。
...正規表現の生成時に指定されたオプションを返します。戻り値は、
Regexp::EXTENDED, Regexp::IGNORECASE,
Regexp::MULTILINE,
Regexp::FIXEDENCODING,
Regexp::NOENCODING,
の論理和です。
これで得られるオプションには生成時に指定したもの以外の
オ......で、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......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
# source -> String (2.0) -
その正規表現のもととなった文字列表現を生成して返します。
その正規表現のもととなった文字列表現を生成して返します。
re = /foo|bar|baz/i
p re.source # => "foo|bar|baz" -
Regexp
# to _ json(*args) -> String (2.0) -
自身を JSON 形式の文字列に変換して返します。
...enerator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数には何の意味もありません。
//emlist[例][ruby]{
require "json/add/core"
/0\d{1,4}-\d{1,4}-\d{4}/.to_json # => "{\"json_class\":\"Regexp\",\"o\":0,\"s\":\"0\\\\d{1,4}-\\\\d{1,4}-\\\\d{4}\"}"
//}... -
Regexp
# to _ s -> String (2.0) -
正規表現の文字列表現を生成して返します。返される文字列は他の正規表 現に埋め込んでもその意味が保持されるようになっています。
...にくくなります。
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
# ~ -> Integer | nil (2.0) -
変数 $_ の値との間でのマッチをとります。
...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... -
Regexp
. compile(string , option = nil , code = nil) -> Regexp (2.0) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp::EXTENDED
の論理和を指定します。
Integer 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp::IGNORECASE...... RegexpError 正規表現のコンパイルに失敗した場合発生します。
str = "This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
puts $~ #=> This is Regexp
t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp......# ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
puts Regexp.last_match #=> This is Regexp
str = "ふるいけや\nかわずとびこむ\nみずのおと"
t2 = Regexp.compile("ふる.*?と", Regexp::MULTILINE)
puts t2.match(str)[0] #=> ふる... -
Regexp
. escape(string) -> String (2.0) -
string の中で正規表現において特別な意味を持つ文字の直前にエ スケープ文字(バックスラッシュ)を挿入した文字列を返します。
...いて特別な意味を持つ文字の直前にエ
スケープ文字(バックスラッシュ)を挿入した文字列を返します。
@param string 正規表現において特別な意味をもつ文字をもつ文字列を指定します。
rp = Regexp.escape("$bc^")
puts rp #=> \$bc\^... -
Regexp
. json _ create(hash) -> Regexp (2.0) -
JSON のオブジェクトから Ruby のオブジェクトを生成して返します。
JSON のオブジェクトから Ruby のオブジェクトを生成して返します。
@param hash 適切なキーを持つハッシュを指定します。 -
Regexp
. last _ match -> MatchData (2.0) -
カレントスコープで最後に行った正規表現マッチの MatchData オ ブジェクトを返します。このメソッドの呼び出しは $~ の参照と同じです。
...ます。このメソッドの呼び出しは $~
の参照と同じです。
/(.)(.)/ =~ "ab"
p Regexp.last_match # => #<MatchData:0x4599e58>
p Regexp.last_match[0] # => "ab"
p Regexp.last_match[1] # => "a"
p Regexp.last_match[2] # => "b"
p Regexp.last_match[3] # => nil... -
Regexp
. last _ match(nth) -> String | nil (2.0) -
整数 nth が 0 の場合、マッチした文字列を返します ($&)。それ以外では、nth 番目の括弧にマッチ した部分文字列を返します($1,$2,...)。 対応する括弧がない場合やマッチしなかった場合には nil を返し ます。
.../ =~ "ab"
p Regexp.last_match # => #<MatchData:0x4599e58>
p Regexp.last_match(0) # => "ab"
p Regexp.last_match(1) # => "a"
p Regexp.last_match(2) # => "b"
p Regexp.last_match(3) # => nil
正規表現全体がマッチしなかった場合、引数なしの
Regexp.last_match......(1) は nil を返します。
str = "This is Regexp"
/That is Regexp/ =~ str
p Regexp.last_match #=> nil
begin
p Regexp.last_match[1] # 例外が発生する
rescue
puts $! #=> undefined method `[]' for nil:NilClass
end
p Regexp.last_match(1) #=> nil
@param nth 整数を指... -
Regexp
. new(string , option = nil , code = nil) -> Regexp (2.0) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp::EXTENDED
の論理和を指定します。
Integer 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp::IGNORECASE...... RegexpError 正規表現のコンパイルに失敗した場合発生します。
str = "This is Regexp"
t1 = Regexp.compile("this is regexp", Regexp::IGNORECASE)
t1.match(str)
puts $~ #=> This is Regexp
t2 = Regexp.compile('
this # ここは使用されない
\ is
\ regexp......# ここも使用されない
', Regexp::EXTENDED | Regexp::IGNORECASE)
t2.match(str)
puts Regexp.last_match #=> This is Regexp
str = "ふるいけや\nかわずとびこむ\nみずのおと"
t2 = Regexp.compile("ふる.*?と", Regexp::MULTILINE)
puts t2.match(str)[0] #=> ふる... -
Regexp
. quote(string) -> String (2.0) -
string の中で正規表現において特別な意味を持つ文字の直前にエ スケープ文字(バックスラッシュ)を挿入した文字列を返します。
...いて特別な意味を持つ文字の直前にエ
スケープ文字(バックスラッシュ)を挿入した文字列を返します。
@param string 正規表現において特別な意味をもつ文字をもつ文字列を指定します。
rp = Regexp.escape("$bc^")
puts rp #=> \$bc\^... -
Regexp
. try _ convert(obj) -> Regexp | nil (2.0) -
obj を to_regexp メソッドで Regexp オブジェクトに変換しようと 試みます。
...obj を to_regexp メソッドで Regexp オブジェクトに変換しようと
試みます。
変換に成功した場合はそれを返し、失敗時には nil を返します。
Regexp.try_convert(/re/) # => /re/
Regexp.try_convert("re") # => nil... -
Regexp
. union(*pattern) -> Regexp (2.0) -
引数として与えた pattern を選択 | で連結し、Regexp として返します。 結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。
...し、Regexp として返します。
結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。
p Regexp.union(/a/, /b/, /c/) #=> /(?-mix:a)|(?-mix:b)|(?-mix:c)/
引数を一つだけ与える場合は、Array を与えても Regexp を......ができます。
arr = [/a/, /b/, /c/]
p Regexp.union(arr) #=> /(?-mix:a)|(?-mix:b)|(?-mix:c)/
# 1.8.7 より前は、以下のように書く必要があった
p Regexp.union(*arr) #=> /(?-mix:a)|(?-mix:b)|(?-mix:c)/
pattern は Regexp または String で与えます。
String で与......結果の Regexp に組み込まれます。
p Regexp.union("a", "?", "b") # => /a|\?|b/
p Regexp.union(/a/, "*") # => /(?-mix:a)|\*/
引数をひとつも与えなかった場合、決してマッチしない Regexp を返します。
p Regexp.union() # => /(?!)/
結果の Regexp が対... -
Regexp
:: EXTENDED -> Integer (2.0) -
バックスラッシュでエスケープされていない空白と # から改行までを無 視します。正規表現リテラルの //x オプションと同じ です。(空白を入れる場合は\でエスケープして\ (<-空白)と 指定します)
バックスラッシュでエスケープされていない空白と # から改行までを無
視します。正規表現リテラルの //x オプションと同じ
です。(空白を入れる場合は\でエスケープして\ (<-空白)と
指定します) -
Regexp
:: FIXEDENCODING -> Integer (2.0) -
正規表現が特定のエンコーディングの文字列にしかマッチしないことを意味します。
...正規表現が特定のエンコーディングの文字列にしかマッチしないことを意味します。
@see Regexp#fixed_encoding?... -
Regexp
:: IGNORECASE -> Integer (2.0) -
文字の大小の違いを無視します。 正規表現リテラルの //i オプションと同じです。
文字の大小の違いを無視します。
正規表現リテラルの //i オプションと同じです。 -
Regexp
:: MULTILINE -> Integer (2.0) -
複数行モード。正規表現 "." が改行にマッチするようになります。 正規表現リテラルの //m オプションと同じです。
複数行モード。正規表現 "." が改行にマッチするようになります。
正規表現リテラルの //m オプションと同じです。 -
Regexp
:: NOENCODING -> Integer (2.0) -
正規表現のマッチ時に文字列のエンコーディングを無視し、 バイト列としてマッチすることを意味します。
正規表現のマッチ時に文字列のエンコーディングを無視し、
バイト列としてマッチすることを意味します。
正規表現リテラルの n オプションに対応します。