検索結果
先頭3件
-
Regexp
. compile(string , option = nil , code = nil) -> Regexp (18120) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp::EXTENDED
の論理和を指定します。
Fixnum 以外であれば真偽値の指定として見なされ
、真(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
. new(string , option = nil , code = nil) -> Regexp (3020) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...@param option Regexp::IGNORECASE, Regexp::MULTILINE,
Regexp::EXTENDED
の論理和を指定します。
Fixnum 以外であれば真偽値の指定として見なされ
、真(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
# ~ -> Fixnum | nil (7) -
変数 $_ の値との間でのマッチをとります。ちょうど以下と同じ意 味です。
...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"...
