From 066b825400349c559aa3c1ca7769516c967c41b9 Mon Sep 17 00:00:00 2001 From: knu Date: Fri, 8 Jan 2016 13:34:52 +0000 Subject: * doc/regexp.rdoc: [DOC] Elaborate on the \G anchor. [ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53467 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- doc/regexp.rdoc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/regexp.rdoc b/doc/regexp.rdoc index 02a5f300ee..4722f2e7f5 100644 --- a/doc/regexp.rdoc +++ b/doc/regexp.rdoc @@ -470,7 +470,19 @@ characters, anchoring the match to a specific position. * \Z - Matches end of string. If string ends with a newline, it matches just before newline * \z - Matches end of string -* \G - Matches point where last match finished +* \G - Matches first matching position: + + In methods like String#gsub and String#scan, it changes on each iteration. + It initially matches the beginning of subject, and in each following iteration it matches where the last match finished. + + " a b c".gsub(/ /, '_') #=> "____a_b_c" + " a b c".gsub(/\G /, '_') #=> "____a b c" + + In methods like Regexp#match and String#match that take an (optional) offset, it matches where the search begins. + + "hello, world".match(/,/, 3) #=> # + "hello, world".match(/\G,/, 3) #=> nil + * \b - Matches word boundaries when outside brackets; backspace (0x08) when inside brackets * \B - Matches non-word boundaries -- cgit v1.2.3