ライブラリ
- ビルトイン (787)
- abbrev (22)
- csv (22)
-
minitest
/ spec (2) -
minitest
/ unit (1) - pathname (11)
-
rdoc
/ markup (22) -
rdoc
/ parser (22) - resolv (77)
- strscan (110)
- uri (33)
-
webrick
/ httputils (22)
クラス
- Array (11)
- CSV (22)
- MatchData (11)
- Module (1)
- NilClass (6)
- Object (21)
- Pathname (11)
-
RDoc
:: Markup (22) -
RDoc
:: Options (22) -
RDoc
:: Parser (22) - Regexp (305)
- Resolv (11)
-
Resolv
:: IPv4 (11) -
Resolv
:: IPv6 (55) - String (239)
- StringScanner (110)
- Symbol (118)
モジュール
- Abbrev (11)
- Kernel (55)
-
MiniTest
:: Assertions (1) - URI (33)
-
WEBrick
:: HTTPUtils (22)
キーワード
-
$ & (11) -
$ & # 39; (11) -
$ -F (11) -
$ ; (11) -
$ ` (11) -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - == (11)
- === (11)
- =~ (26)
- AddressRegex (11)
- DateMatcher (11)
- DateTimeMatcher (11)
- EXTENDED (11)
- FIXEDENCODING (11)
- IGNORECASE (11)
-
LABEL
_ LIST _ RE (11) - MULTILINE (11)
- MatchData (11)
-
NEWS for Ruby 2
. 5 . 0 (7) - NOENCODING (11)
- Regex (22)
-
Regex
_ 6Hex4Dec (11) -
Regex
_ 8Hex (11) -
Regex
_ CompressedHex (11) -
Regex
_ CompressedHex4Dec (11) - RegexpError (11)
- Rubyで使われる記号の意味(正規表現の複雑な記号は除く) (11)
- Ruby用語集 (11)
-
SEPARATOR
_ PAT (11) -
SIMPLE
_ LIST _ RE (11) - UNSAFE (11)
- [] (121)
- []= (77)
- abbrev (22)
-
assert
_ match (1) - casefold? (11)
- check (11)
-
check
_ until (11) - compile (11)
- encoding (11)
- eql? (11)
- escape (22)
-
escape
_ path (11) - exclude (11)
- exist? (11)
-
extra
_ accessors (11) -
fixed
_ encoding? (11) - hash (11)
-
infect
_ with _ assertions (1) -
last
_ match (22) - match (44)
- match? (35)
-
must
_ match (1) -
named
_ captures (11) - names (11)
- new (11)
-
parse
_ files _ matching (11) - parsers (11)
- quote (11)
- regexp (33)
-
ruby 1
. 6 feature (11) -
ruby 1
. 8 . 2 feature (11) -
ruby 1
. 9 feature (11) -
rubygems
/ commands / query _ command (11) - scan (11)
-
scan
_ full (11) -
scan
_ until (11) -
search
_ full (11) - skip (11)
-
skip
_ until (11) - slice (121)
- source (11)
-
to
_ regexp (11) -
to
_ s (11) - union (11)
- リテラル (11)
- 多言語化 (11)
検索結果
先頭5件
-
Regexp (38104.0)
-
正規表現のクラス。正規表現のリテラルはスラッシュで囲んだ形式 で記述します。
...正規表現のクラス。正規表現のリテラルはスラッシュで囲んだ形式
で記述します。
//emlist[][ruby]{
/^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"
//}
spec/regexp や d:spec/literal#regexp も参照してください。......xp"
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('ab......c').frozen?
# => false
//}
spec/regexp や d:spec/literal#regexp も参照してください。... -
Regexp
. union(*pattern) -> Regexp (21289.0) -
引数として与えた pattern を選択 | で連結し、Regexp として返します。 結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。
...引数として与えた pattern を選択 | で連結し、Regexp として返します。
結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。
//emlist[][ruby]{
p Regexp.union(/a/, /b/, /c/) # => /(?-mix:a)|(?-mix:b)|(?-mix:c)/
//}......ay を与えても Regexp を生成します。
つまり、以下のように書くことができます。
//emlist[][ruby]{
arr = [/a/, /b/, /c/]
p Regexp.union(arr) # => /(?-mix:a)|(?-mix:b)|(?-mix:c)/
# 1.8.7 より前は、以下のように書く必要があった
p Regexp.union(*arr) # =>......る Regexp とコードが固定されていない Regexp を混ぜた場合、
結果の Regexp は固定されているコードに対応するものになります。
//emlist[][ruby]{
p Regexp.union(/a/e, /b/) # => /(?-mix:a)|(?-mix:b)/e
//}
@param pattern | で連結したい正規表現を... -
Regexp
. compile(string , option = nil , code = nil) -> Regexp (21244.0) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...して正規表現オブジェクトを生成して返します。
第一引数が正規表現であれば第一引数を複製して返します。第二、第三引数は警告の上無視されます。
@param string 正規表現を文字列として与えます。
@param option Regexp::IGNORE......CASE, Regexp::MULTILINE,
Regexp::EXTENDED
の論理和を指定します。
Integer 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp::IGNORECASE の指定と同じになりま......れた正規表現のエンコーディングは ASCII-8BIT になります。
それ以外の指定は警告を出力します。
@raise RegexpError 正規表現のコンパイルに失敗した場合発生します。
//emlist[例][ruby]{
str = "This is Regexp"
t1 = Regexp.compile("... -
Regexp
. new(string , option = nil , code = nil) -> Regexp (21244.0) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...して正規表現オブジェクトを生成して返します。
第一引数が正規表現であれば第一引数を複製して返します。第二、第三引数は警告の上無視されます。
@param string 正規表現を文字列として与えます。
@param option Regexp::IGNORE......CASE, Regexp::MULTILINE,
Regexp::EXTENDED
の論理和を指定します。
Integer 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp::IGNORECASE の指定と同じになりま......れた正規表現のエンコーディングは ASCII-8BIT になります。
それ以外の指定は警告を出力します。
@raise RegexpError 正規表現のコンパイルに失敗した場合発生します。
//emlist[例][ruby]{
str = "This is Regexp"
t1 = Regexp.compile("... -
Regexp
# options -> Integer (21222.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
. last _ match(nth) -> String | nil (21078.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 は......を返します。
//emlist[例][ruby]{
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
. last _ match -> MatchData (21058.0) -
カレントスコープで最後に行った正規表現マッチの MatchData オ ブジェクトを返します。このメソッドの呼び出しは $~ の参照と同じです。
...に行った正規表現マッチの MatchData オ
ブジェクトを返します。このメソッドの呼び出しは $~
の参照と同じです。
//emlist[例][ruby]{
/(.)(.)/ =~ "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
# match(str , pos = 0) -> MatchData | nil (21040.0) -
指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。
...指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ
チングを行います。マッチした場合には結果を MatchData オブジェクトで返し
ます。
マッチしなかった場合 nil を返します。
省略可能な第二引数 pos......r 文字列を指定します。str との正規表現マッチを行います。
@param pos 整数を指定します。マッチの開始位置を pos から行うよう制御できます(pos のデフォルト値は 0)。
//emlist[例][ruby]{
reg = Regexp.new("foo")
if reg.match("foobar")
put......match("bar") # => nil
p /(foo)(bar)(baz)/.match("foobarbaz").to_a.values_at(1,2,3) # => ["foo", "bar", "baz"]
//}
=== 便利な使いかた
正規表現にマッチした部分文字列だけが必要な場合に、
//emlist[][ruby]{
bar = /foo(.*)baz/.match("foobarbaz").to_a[1]
foo, bar, baz... -
Regexp
# match(str , pos = 0) {|m| . . . } -> object | nil (21040.0) -
指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。
...指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ
チングを行います。マッチした場合には結果を MatchData オブジェクトで返し
ます。
マッチしなかった場合 nil を返します。
省略可能な第二引数 pos......r 文字列を指定します。str との正規表現マッチを行います。
@param pos 整数を指定します。マッチの開始位置を pos から行うよう制御できます(pos のデフォルト値は 0)。
//emlist[例][ruby]{
reg = Regexp.new("foo")
if reg.match("foobar")
put......match("bar") # => nil
p /(foo)(bar)(baz)/.match("foobarbaz").to_a.values_at(1,2,3) # => ["foo", "bar", "baz"]
//}
=== 便利な使いかた
正規表現にマッチした部分文字列だけが必要な場合に、
//emlist[][ruby]{
bar = /foo(.*)baz/.match("foobarbaz").to_a[1]
foo, bar, baz... -
Regexp
# casefold? -> bool (21034.0) -
正規表現が大文字小文字の判定をしないようにコンパイルされている時、 真を返します。
...
正規表現が大文字小文字の判定をしないようにコンパイルされている時、
真を返します。
//emlist[例][ruby]{
reg = Regexp.new("foobar", Regexp::IGNORECASE)
p reg.casefold? # => true
reg = Regexp.new("hogehoge")
p reg.casefold? # => false
//}...