55件ヒット
[1-55件を表示]
(0.053秒)
検索結果
先頭5件
-
Regexp
# match(str , pos = 0) -> MatchData | nil (27324.0) -
指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。
...字列 str に対して位置 pos から自身が表す正規表現によるマッ
チングを行います。マッチした場合には結果を MatchData オブジェクトで返し
ます。
マッチしなかった場合 nil を返します。
省略可能な第二引数 pos を指定すると......captures) # => ["b", "r"]
p(/(.).(.)/.match("foobar", -3).captures) # => ["b", "r"]
//}
pos を指定しても MatchData#offset 等の結果
には影響しません。つまり、
//emlist[][ruby]{
re.match(str[pos..-1])
//}
と
//emlist[][ruby]{
re.match(str, pos)
//}
は異なります。......チした場合に限り MatchData オブジェクトがブロック引数に渡されて実行されます。
マッチした場合はブロックの値を返し、マッチしなかった場合は nil を返します。
//emlist[例][ruby]{
results = []
/((.)\2)/.match("foo") {|m| results << m[0]... -
Regexp
# match(str , pos = 0) {|m| . . . } -> object | nil (27224.0) -
指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。
...字列 str に対して位置 pos から自身が表す正規表現によるマッ
チングを行います。マッチした場合には結果を MatchData オブジェクトで返し
ます。
マッチしなかった場合 nil を返します。
省略可能な第二引数 pos を指定すると......captures) # => ["b", "r"]
p(/(.).(.)/.match("foobar", -3).captures) # => ["b", "r"]
//}
pos を指定しても MatchData#offset 等の結果
には影響しません。つまり、
//emlist[][ruby]{
re.match(str[pos..-1])
//}
と
//emlist[][ruby]{
re.match(str, pos)
//}
は異なります。......チした場合に限り MatchData オブジェクトがブロック引数に渡されて実行されます。
マッチした場合はブロックの値を返し、マッチしなかった場合は nil を返します。
//emlist[例][ruby]{
results = []
/((.)\2)/.match("foo") {|m| results << m[0]... -
Regexp
. new(string , option = nil , code = nil) -> Regexp (24331.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)[0] # => "... -
Regexp
. compile(string , option = nil , code = nil) -> Regexp (9231.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)[0] # => "... -
Regexp (6086.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 も参照してください。......]{
/^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 も参照してください。...