[ruby-core:85786] [Ruby trunk Misc#14500] Missing Regexp documentation and clarification on behavior of \K for edge case

From: learnbyexample.net@...
Date: 2018-02-24 02:13:33 UTC
List: ruby-core #85786
Issue #14500 has been updated by Sundeep (Sundeep Agarwal).


oh, I didn't check with `$10`. I'd tried with backreference. Any idea how to use `\10`?

```
$ echo 'abcdefghij' | ruby -pe 'sub(/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)/, ":\\9:")'
:i:
$ echo 'abcdefghij' | ruby -pe 'sub(/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)/, ":\\10:")'
:a0:
$ echo 'abcdefghij' | ruby -pe 'sub(/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)/){":#{$10}:"}'
:j:
```

----------------------------------------
Misc #14500: Missing Regexp documentation and clarification on behavior of \K for edge case
https://bugs.ruby-lang.org/issues/14500#change-70635

* Author: Sundeep (Sundeep Agarwal)
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
**Capturing** section (https://ruby-doc.org/core-2.5.0/Regexp.html#class-Regexp-label-Capturing)

* formatting issue: `n<sup>th</sup>`
* suggestion to add a note on `\0` similar to the note mentioned in **Special global variables** (https://ruby-doc.org/core-2.5.0/Regexp.html#class-Regexp-label-Special+global+variables) section about `$&`
* suggestion to add that numbered capturing groups is limited to `9`

**Anchors** section (https://ruby-doc.org/core-2.5.0/Regexp.html#class-Regexp-label-Anchors)

* suggestion to add documentation on `\K`
* need clarification if the below behavior seen is expected and mention it while adding documentation

```
$ echo 'aaa' | ruby -pe 'gsub(/a\K/, ":")'
a:aa:

$ # what I expected
$ echo 'aaa' | ruby -pe 'gsub(/(a)/, "\\1:")'
a:a:a:
```




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next