55件ヒット
[1-55件を表示]
(0.097秒)
検索結果
先頭5件
-
Regexp
# match(str , pos = 0) -> MatchData | nil (26312.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 (26212.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 (23127.0) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...s 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] # => "ふるいけや\nかわずと"
//}... -
Regexp
. compile(string , option = nil , code = nil) -> Regexp (8027.0) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...s 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] # => "ふるいけや\nかわずと"
//}... -
Regexp (8026.0)
-
正規表現のクラス。正規表現のリテラルはスラッシュで囲んだ形式 で記述します。
...by]{
/^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"
//}
sp......by]{
/^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"
//}
Rub......y 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 も参照してください。...