[前][次][番号順一覧][スレッド一覧]

ruby-changes:41395

From: knu <ko1@a...>
Date: Fri, 8 Jan 2016 22:34:37 +0900 (JST)
Subject: [ruby-changes:41395] knu:r53467 (trunk): * doc/regexp.rdoc: [DOC] Elaborate on the \G anchor. [ci skip]

knu	2016-01-08 22:34:52 +0900 (Fri, 08 Jan 2016)

  New Revision: 53467

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53467

  Log:
    * doc/regexp.rdoc: [DOC] Elaborate on the \G anchor. [ci skip]

  Modified files:
    trunk/ChangeLog
    trunk/doc/regexp.rdoc
Index: doc/regexp.rdoc
===================================================================
--- doc/regexp.rdoc	(revision 53466)
+++ doc/regexp.rdoc	(revision 53467)
@@ -470,7 +470,19 @@ characters, <i>anchoring</i> the match t https://github.com/ruby/ruby/blob/trunk/doc/regexp.rdoc#L470
 * <tt>\Z</tt> - Matches end of string. If string ends with a newline,
   it matches just before newline
 * <tt>\z</tt> - Matches end of string
-* <tt>\G</tt> - Matches point where last match finished
+* <tt>\G</tt> - Matches first matching position:
+
+  In methods like <tt>String#gsub</tt> and <tt>String#scan</tt>, 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 <tt>Regexp#match</tt> and <tt>String#match</tt> that take an (optional) offset, it matches where the search begins.
+
+      "hello, world".match(/,/, 3)    #=> #<MatchData ",">
+      "hello, world".match(/\G,/, 3)  #=> nil
+
 * <tt>\b</tt> - Matches word boundaries when outside brackets;
   backspace (0x08) when inside brackets
 * <tt>\B</tt> - Matches non-word boundaries
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53466)
+++ ChangeLog	(revision 53467)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jan  8 22:30:06 2016  Akinori MUSHA  <knu@i...>
+
+	* doc/regexp.rdoc: [DOC] Elaborate on the \G anchor. [ci skip]
+
 Fri Jan  8 19:49:27 2016  Koichi Sasada  <ko1@a...>
 
 	* gc.c: remove heap_page::body. Instead of this field,

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]