ライブラリ
- ビルトイン (603)
- csv (24)
- etc (12)
-
json
/ add / regexp (24) -
minitest
/ spec (2) -
minitest
/ unit (1) - pathname (12)
-
rdoc
/ markup (24) -
rdoc
/ parser (24) - resolv (84)
- scanf (6)
- strscan (120)
- uri (36)
クラス
- CSV (24)
- MatchData (12)
- Module (1)
- Object (13)
- Pathname (12)
-
RDoc
:: Markup (24) -
RDoc
:: Options (24) -
RDoc
:: Parser (24) - Regexp (393)
- Resolv (12)
-
Resolv
:: IPv4 (12) -
Resolv
:: IPv6 (60) -
Scanf
:: FormatString (6) - String (129)
- StringScanner (120)
- Symbol (33)
モジュール
- Etc (12)
- Kernel (24)
-
MiniTest
:: Assertions (1) - URI (36)
キーワード
-
$ -F (12) -
$ ; (12) - == (12)
- === (12)
- =~ (12)
- AddressRegex (12)
- DateMatcher (12)
- DateTimeMatcher (12)
- EXTENDED (12)
- FIXEDENCODING (12)
- IGNORECASE (12)
-
LABEL
_ LIST _ RE (12) - MULTILINE (12)
- NOENCODING (12)
- REGEX (6)
- RREGEXP (12)
-
Regex
_ 6Hex4Dec (12) -
Regex
_ 8Hex (12) -
Regex
_ CompressedHex (12) -
Regex
_ CompressedHex4Dec (12) - Regexp (12)
- RegexpError (12)
-
SC
_ REGEXP (12) -
SEPARATOR
_ PAT (12) -
SIMPLE
_ LIST _ RE (12) - UNSAFE (12)
- [] (36)
- []= (36)
-
assert
_ match (1) - casefold? (12)
- check (12)
-
check
_ until (12) - compile (12)
- encoding (12)
- eql? (12)
- escape (12)
- exclude (12)
- exist? (12)
-
extra
_ accessors (12) -
fixed
_ encoding? (12) - hash (12)
-
infect
_ with _ assertions (1) - inspect (12)
-
json
/ add / regexp (12) -
json
_ create (12) -
last
_ match (24) - match (48)
- match? (39)
-
must
_ match (1) -
named
_ captures (12) - names (12)
- new (12)
-
parse
_ files _ matching (12) - parsers (12)
- quote (12)
- regexp (36)
-
ruby 1
. 8 . 4 feature (12) - scan (12)
-
scan
_ full (12) -
scan
_ until (12) -
search
_ full (12) - skip (12)
-
skip
_ until (12) - slice (36)
- slice! (12)
- source (12)
-
to
_ json (12) -
to
_ regexp (12) -
to
_ s (12) -
try
_ convert (12) - union (12)
- ~ (12)
- 正規表現 (12)
検索結果
先頭5件
-
Regexp (26000.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 も参照してください。......y]{
/^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 も参照してください。... -
RegexpError (26000.0)
-
正規表現のコンパイルに失敗したときに発生します。
...正規表現のコンパイルに失敗したときに発生します。
例:
$ ruby -e 'Regexp.compile("*")'
-e:1:in `initialize': target of repeat operator is not specified: /*/ (RegexpError)
from -e:1:in `Regexp#compile'
from -e:1... -
Regexp
. compile(string , option = nil) -> Regexp (23100.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
. compile(string , option = nil , code = nil) -> Regexp (23100.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
. json _ create(hash) -> Regexp (23100.0) -
JSON のオブジェクトから Ruby のオブジェクトを生成して返します。
JSON のオブジェクトから Ruby のオブジェクトを生成して返します。
@param hash 適切なキーを持つハッシュを指定します。 -
Regexp
. new(string , option = nil) -> Regexp (23100.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 (23100.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
. try _ convert(obj) -> Regexp | nil (23100.0) -
obj を to_regexp メソッドで Regexp オブジェクトに変換しようと 試みます。
...obj を to_regexp メソッドで Regexp オブジェクトに変換しようと
試みます。
変換に成功した場合はそれを返し、失敗時には nil を返します。
//emlist[例][ruby]{
Regexp.try_convert(/re/) # => /re/
Regexp.try_convert("re") # => nil
//}... -
Regexp
. union(*pattern) -> Regexp (23100.0) -
引数として与えた pattern を選択 | で連結し、Regexp として返します。 結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。
...引数として与えた pattern を選択 | で連結し、Regexp として返します。
結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。
//emlist[][ruby]{
p Regexp.union(/a/, /b/, /c/) # => /(?-mix:a)|(?-mix:b)|(?-mix:c)/
//}......ray を与えても Regexp を生成します。
つまり、以下のように書くことができます。
//emlist[][ruby]{
arr = [/a/, /b/, /c/]
p Regexp.union(arr) # => /(?-mix:a)|(?-mix:b)|(?-mix:c)/
# 1.8.7 より前は、以下のように書く必要があった
p Regexp.union(*arr) # =>......ern は Regexp または String で与えます。
String で与えた場合、それ自身と等しい文字列にマッチするものと解釈され、
エスケープされて結果の Regexp に組み込まれます。
//emlist[][ruby]{
p Regexp.union("a", "?", "b") # => /a|\?|b/
p Regexp.unio... -
Regexp
# ~ -> Integer | nil (23006.0) -
変数 $_ の値との間でのマッチをとります。
...ruby]{
$_ = "hogehoge"
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... -
Regexp
# ==(other) -> bool (23000.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
//}...