るりまサーチ

最速Rubyリファレンスマニュアル検索!
775件ヒット [101-200件を表示] (0.102秒)

別のキーワード

  1. fiddle ruby_free
  2. rbconfig ruby
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

クラス

キーワード

検索結果

<< < 1 2 3 4 ... > >>

Regexp#=~(string) -> Integer | nil (12143.0)

文字列 string との正規表現マッチを行います。マッチした場合、 マッチした位置のインデックスを返します(先頭は0)。マッチしなかった 場合、あるいは string が nil の場合には nil を返 します。

...文字列 string との正規表現マッチを行います。マッチした場合、
マッチした位置のインデックスを返します(先頭は0)。マッチしなかった
場合、あるいは string が nil の場合には nil を返
します。

//emlist[例][ruby]{
p /foo/ =~ "foo"...
...bar" # => nil
//}

組み込み変数 $~ もしくは Regexp.last_match にマッチに関する情報 MatchData が設定されます。

文字列のかわりにSymbolをマッチさせることができます。

@param string マッチ対象文字列

@raise TypeError string が nil でも Stri...
...t[例][ruby]{
p /foo/ =~ "foo" # => 0
p Regexp.last_match(0) # => "foo"
p /foo/ =~ "afoo" # => 1
p $~[0] # => "foo"
p /foo/ =~ "bar" # => nil

unless /foo/ === "bar"
puts "not match " # => not match
end

str = []
begin
/ugo/ =~ str
r
escue TypeError
printf "...

Regexp#to_s -> String (12143.0)

正規表現の文字列表現を生成して返します。返される文字列は他の正規表 現に埋め込んでもその意味が保持されるようになっています。

...現に埋め込んでもその意味が保持されるようになっています。

//emlist[][ruby]{
r
e = /foo|bar|baz/i
p re.to_s # => "(?i-mx:foo|bar|baz)"
p /#{re}+/o # => /(?i-mx:foo|bar|baz)+/
//}

ただし、後方参照を含む正規表現は意図通りにはならない場合...
.../emlist[][ruby]{
r
e = /(foo|bar)\1/ # \1 は、foo か bar
p /(baz)#{re}/ # \1 は、baz

# => /(baz)(?-mix:(foo|bar)\1)/
//}

//emlist[使用例][ruby]{
r
e = /foo|bar|baz/i
p re.to_s # => "(?i-mx:foo|bar|baz)"
p /#{re}+/o # => /(?i-mx:foo|bar|baz)+/
//}

@see Regexp#inspect...

Regexp#inspect -> String (12135.0)

Regexp#to_s より自然な文字列を返します。

...Regexp#to_s より自然な文字列を返します。

//emlist[例][ruby]{
p /^ugou.*?/i.to_s # => "(?i-mx:^ugou.*?)"
p /^ugou.*?/i.inspect # => "/^ugou.*?/i"
//}

@see Regexp#to_s...

Regexp#~ -> Integer | nil (12131.0)

変数 $_ の値との間でのマッチをとります。

...][ruby]{
self =~ $_
//}

//emlist[例][ruby]{
$_ = "hogehoge"

if /foo/
puts "match"
else
puts "no match"
end
# => no match
# ただし、警告がでる。warning: regex literal in condition

r
eg = Regexp.compile("foo")

if ~ reg
puts "match"
else
puts "no match"
end
# => no match

if re...
...g
puts "match"
else
puts "no match"
end
# => match
# reg は nil でも false でも無いので常にtrue
//}...

Regexp#fixed_encoding? -> bool (12121.0)

正規表現が任意の ASCII 互換エンコーディングとマッチ可能な時に false を返します。

...][ruby]{
# -*- coding:utf-8 -*-

r
= /a/
r
.fixed_encoding? # => false
r
.encoding # => #<Encoding:US-ASCII>
r
=~ "\u{6666} a" # => 2
r
=~ "\xa1\xa2 a".force_encoding("euc-jp") # => 2
r
=~ "abc".force...
..."euc-jp") # => 0

r
= /a/u
r
.fixed_encoding? # => true
r
.encoding # => #<Encoding:UTF-8>
r
=~ "\u{6666} a" # => 2
begin
r
=~ "\xa1\xa2".force_encoding("euc-jp")
r
escue => e
e.class...
...lityError
end
r
=~ "abc".force_encoding("euc-jp") # => 0

r
= /\u{6666}/
r
.fixed_encoding? # => true
r
.encoding # => #<Encoding:UTF-8>
r
=~ "\u{6666} a" # => 0
begin
r
=~ "\xa1\xa2".force_e...

絞り込み条件を変える

Regexp#==(other) -> bool (12119.0)

otherが同じパターン、オプション、文字コードの正規表現であったらtrueを返します。

...otherが同じパターン、オプション、文字コードの正規表現であったら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
//}...

Regexp#eql?(other) -> bool (12119.0)

otherが同じパターン、オプション、文字コードの正規表現であったらtrueを返します。

...otherが同じパターン、オプション、文字コードの正規表現であったら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
//}...

Regexp#to_json(*args) -> String (12119.0)

自身を JSON 形式の文字列に変換して返します。

...ットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。

@param args 引数には何の意味もありません。

//emlist[例][ruby]{
r
equire "json/add/core"

/0\d{1,4}-\d{1,4}-\d{4}/.to_json # => "{\"json_class\":\"Regexp\",\"o\":0,\"s\":\"0\\\\d{1,4}-\\...
...nerator::GeneratorMethods::Hash#to_json を呼び出しています。

@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json
に渡されます。

//emlist[例][ruby]{
r
equire "json/add/core"

/0\d{1,4}-\d{1,4}-\d{4}/.to_json # => "{\"json_class\":\"Regexp\"...

Regexp#===(string) -> bool (12113.0)

文字列 string との正規表現マッチを行います。 マッチした場合は真を返します。

...文字列 string との正規表現マッチを行います。
マッチした場合は真を返します。

string が文字列でもシンボルでもない場合には false を返します。

このメソッドは主にcase文での比較に用いられます。

@param string マッチ対象...
...文字列

//emlist[例][ruby]{
a = "HELLO"
case a
when /\A[a-z]*\z/; puts "Lower case"
when /\A[A-Z]*\z/; puts "Upper case"
else; puts "Mixed case"
end
# => Upper case

/\A[a-z]*\z/ === "HELLO" # => false
/\A[A-Z]*\z/ === "HELLO" # => true
//}

@see Enumerable#grep, Object#===...
<< < 1 2 3 4 ... > >>