57件ヒット
[1-57件を表示]
(0.032秒)
種類
- 特異メソッド (22)
- 変数 (11)
- 文書 (11)
- クラス (11)
- インスタンスメソッド (2)
モジュール
- Kernel (11)
キーワード
- StringScanner (11)
- byterindex (2)
- compile (11)
- new (11)
-
ruby 1
. 6 feature (11)
検索結果
先頭5件
-
Kernel
$ $ ~ -> MatchData | nil (18214.0) -
現在のスコープで最後に成功したマッチに関する MatchDataオブジェクトです。 Regexp.last_match の別名です。
...目のマッチ ($n) を取り出すためには $~[n] を使います。
この値に代入すると Regexp.last_match や、 $&, $1, $2, ... などの関連する組み込み変数の値が変化します。
MatchData オブジェクトでも nil でもない値を代入しようとすると Type......ます。
この変数はローカルスコープかつスレッドローカルです。
Ruby起動時の初期値は nil です。
//emlist[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
if %r[<a href="(.*?)">(.*?)</a>] =~ str
p $~[1]
end
#=> "http://example.com"
//}... -
ruby 1
. 6 feature (330.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
... nil
を返すようになりました。(String#[]やString#slice と同じ結果を返すと
いうことです)
p "foo".slice!("bar") # <- 以前からこちらは nil を返していた
p "foo".slice!(5,10)
=> ruby 1.6.7 (2002-03-01) [i586-linux]
nil......: index 5 out of string (IndexError)
from -:2
=> ruby 1.6.7 (2002-08-01) [i586-linux]
nil
nil
: 2002-07-05 String#split
最初の引数に nil を指定できるようになりました。((<ruby-talk:43513>))
この場合、$; を分割文字列......((<組み込み変数/$~>))
$~ に nil を代入できないバグが修正されました。((<ruby-dev:16697>))
/foo/ =~ "foo"
p $~
$~ = nil
p $~
=> ruby 1.6.7 (2002-03-01) [i586-linux]
#<MatchData:0x401b1be4>
-:3: wrong argument type nil (expected Match) (Typ... -
Regexp
. compile(string , option = nil , code = nil) -> Regexp (216.0) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...の論理和を指定します。
Integer 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp::IGNORECASE の指定と同じになります。
@param code "n", "N" が与えられた時には......した場合発生します。
//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::... -
Regexp
. new(string , option = nil , code = nil) -> Regexp (216.0) -
文字列 string をコンパイルして正規表現オブジェクトを生成して返します。
...の論理和を指定します。
Integer 以外であれば真偽値の指定として見なされ
、真(nil, false 以外)であれば
Regexp::IGNORECASE の指定と同じになります。
@param code "n", "N" が与えられた時には......した場合発生します。
//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::... -
String
# byterindex(pattern , offset = self . bytesize) -> Integer | nil (165.0) -
文字列のバイト単位のインデックス offset から左に向かって pattern を探索します。 最初に見つかった部分文字列の左端のバイト単位のインデックスを返します。 見つからなければ nil を返します。
...索します。
最初に見つかった部分文字列の左端のバイト単位のインデックスを返します。
見つからなければ nil を返します。
引数 pattern は探索する部分文字列または正規表現で指定します。
offset が負の場合は、文字列の......o'.byterindex('oo') # => 1
'foo'.byterindex('ooo') # => nil
'foo'.byterindex(/f/) # => 0
'foo'.byterindex(/o/) # => 2
'foo'.byterindex(/oo/) # => 1
'foo'.byterindex(/ooo/) # => nil
# 右でのマッチが優先
'foo'.byterindex(/o+/) # => 2
$~ #=> #<MatchData "o">
# 最長にするには否定戻......d)と組み合わせる
'foo'.byterindex(/(?<!o)o+/) # => 1
$~ #=> #<MatchData "oo">
# またはbyteindexを否定先読み(negative look-ahead)
'foo'.byteindex(/o+(?!.*o)/) # => 1
$~ #=> #<MatchData "oo">
'foo'.byterindex('o', 0) # => nil
'foo'.byterindex('o', 1) # => 1
'foo'.byterindex('o', 2) #... -
StringScanner (48.0)
-
StringScanner は文字列スキャナクラスです。 簡単に高速なスキャナを記述できます。
...ngScanner.new('This is an example string')
s.eos? #=> false
p s.scan(/\w+/) #=> "This"
p s.scan(/\w+/) #=> nil
p s.scan(/\s+/) #=> " "
p s.scan(/\s+/) #=> nil
p s.scan(/\w+/) #=> "is"
s.eos? #=> false
p s.scan(/\s+/) #=> " "
p s.scan(/\w+/) #=> "an"
p s.scan(/\s.......scan(/\w+/) #=> "example"
p s.scan(/\s+/) #=> " "
p s.scan(/\w+/) #=> "string"
s.eos? #=> true
p s.scan(/\s+/) #=> nil
p s.scan(/\w+/) #=> nil
//}
StringScanner オブジェクトはスキャンする文字列と「スキャンポインタ」のセットです。
スキャン......ng=euc-jp:
require 'strscan'
s = StringScanner.new("るびい") # 文字コードはEUC-JPとします
p s.exist?(/び/) #=> 4
//}
StringScanner は $~ $& $1 $2 …… などの正規表現関連変数を
セットしません。代わりに StringScanner#[] , StringScanner#matched? などの
マ...