U:RDoc::AnyMethod[iI"sub:ETI"String#sub;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [
I"FReturns a copy of +str+ with the _first_ occurrence of +pattern+ ;TI"Nreplaced by the second argument. The +pattern+ is typically a Regexp; if ;TI"Ogiven as a String, any regular expression metacharacters it contains will ;TI"Obe interpreted literally, e.g. '\\\d'
will match a backslash ;TI")followed by 'd', instead of a digit.;To:RDoc::Markup::BlankLine o;
; [I"OIf +replacement+ is a String it will be substituted for the matched text. ;TI"PIt may contain back-references to the pattern's capture groups of the form ;TI">"\\d"
, where d is a group number, or ;TI"G"\\k"
, where n is a group name. If it is a ;TI"Gdouble-quoted string, both back-references must be preceded by an ;TI"Kadditional backslash. However, within +replacement+ the special match ;TI"Nvariables, such as $&
, will not refer to the current match. ;TI"PIf +replacement+ is a String that looks like a pattern's capture group but ;TI"Nis actually not a pattern capture group e.g. "\\'"
, then it ;TI"Nwill have to be preceded by two backslashes like so "\\\\'"
.;T@o;
; [I"PIf the second argument is a Hash, and the matched text is one of its keys, ;TI"7the corresponding value is the replacement string.;T@o;
; [ I"NIn the block form, the current match string is passed in as a parameter, ;TI"Nand variables such as $1
, $2
, $`
, ;TI"O$&
, and $'
will be set appropriately. The value ;TI"Jreturned by the block will be substituted for the match on each call.;T@o;
; [I"MThe result inherits any tainting in the original string or any supplied ;TI"replacement string.;T@o:RDoc::Markup::Verbatim; [I">"hello".sub(/[aeiou]/, '*') #=> "h*llo"
;TI"@"hello".sub(/([aeiou])/, '<\1>') #=> "hllo"
;TI"A"hello".sub(/./) {|s| s.ord.to_s + ' ' } #=> "104 ello"
;TI"@"hello".sub(/(?[aeiou])/, '*\k*') #=> "h*e*llo"
;TI"B'Is SHELL your preferred shell?'.sub(/[[:upper:]]{2,}/, ENV)
;TI". #=> "Is /bin/bash your preferred shell?";T:@format0:
@fileI"
string.c;T:0@omit_headings_from_table_of_contents_below0I"“str.sub(pattern, replacement) -> new_str
str.sub(pattern, hash) -> new_str
str.sub(pattern) {|match| block } -> new_str
;T0[ I"(*args);T@5FI"String;TcRDoc::NormalClassI"
scanf;T0