Name
String
Description
String objects contain built-in methods for regular expression pattern matching and substitution, as well as several methods for string manipulation that take regular expressions as arguments.
Instance Methods
string=~regexp=> fixnum or nilMatch the
regexp, and return the position that the match starts, ornil.regexp===string=> booleanReturn true if the
regexpmatches thestring. Used in case-when statements.gsub(pattern,replacement) => new_stringgsub(pattern) {|match| block } => new_stringReturn a copy of
stringwith all occurrences ofpatternreplaced withreplacement, or the value of the block. Otherwise, behaves asRegexp#sub.gsub!(pattern, replacement) => string or nilgsub!(pattern) {|match| block } => string or nilPerform the substitutions of
String#gsubin place, returning string or returningnilif no substitutions were performed.index(regexp[,offset]) => fixnum or nilReturn the index of the first match by
regexpornilif not found. Optionally,offsetspecifies the position in the string to begin the search.match(pattern) => matchdata or nilApply a regex
patternorRegexpobject to the string, returning aMatchDataobject, or returningnilif there was no match.rindex(regexp[, fixnum]) => fixnum or nilReturn the index of the first match by
regexpornilif not found. Optionally,offsetspecifies the position in the string to end the search; characters to the right of this point will not be considered.scan(regexp) => arrayscan(regexp) {|match, ...| block ...