From e021754db013ca9cd6dbd68b416425b32ee81490 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Fri, 15 Apr 2022 13:31:15 -0500 Subject: [DOC] Enhanced RDoc for Regexp (#5807) Treats: #source #inspect #to_s #casefold? #options #names #named_captures --- doc/regexp.rdoc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'doc/regexp.rdoc') diff --git a/doc/regexp.rdoc b/doc/regexp.rdoc index 65d8cd46fa..b8efc7e3d4 100644 --- a/doc/regexp.rdoc +++ b/doc/regexp.rdoc @@ -35,7 +35,7 @@ exceeded. See "Timeout" section in detail. Pattern matching may be achieved by using =~ operator or Regexp#match method. -=== =~ operator +=== =~ Operator =~ is Ruby's basic pattern-matching operator. When one operand is a regular expression and the other is a string then the regular expression is @@ -54,7 +54,7 @@ Using =~ operator with a String and Regexp the $~ global variable is set after a successful match. $~ holds a MatchData object. Regexp.last_match is equivalent to $~. -=== Regexp#match method +=== Regexp#match Method The #match method returns a MatchData object: @@ -193,7 +193,7 @@ At least one uppercase character ('H'), at least one lowercase character "Hello".match(/[[:upper:]]+[[:lower:]]+l{2}o/) #=> # -=== Greedy match +=== Greedy Match Repetition is greedy by default: as many occurrences as possible are matched while still allowing the overall match to succeed. By @@ -211,7 +211,7 @@ Both patterns below match the string. The first uses a greedy quantifier so /<.+>/.match("") #=> #"> /<.+?>/.match("") #=> #"> -=== Possessive match +=== Possessive Match A quantifier followed by + matches possessively: once it has matched it does not backtrack. They behave like greedy quantifiers, @@ -256,7 +256,7 @@ this backreference when doing substitution: "The cat sat in the hat".gsub(/[csh]at/, '\0s') # => "The cats sats in the hats" -=== Named captures +=== Named Captures Capture groups can be referred to by name when defined with the (?<name>) or (?'name') @@ -672,7 +672,7 @@ regexp's encoding can be explicitly fixed by supplying # raises Encoding::CompatibilityError: incompatible encoding regexp match # (ISO-8859-1 regexp with UTF-8 string) -== Special global variables +== Special Global Variables Pattern matching sets some global variables : * $~ is equivalent to Regexp.last_match; -- cgit v1.2.3