Skip to content

Commit 5e3b62f

Browse files
pryrtdonho
authored andcommitted
backreference vs substitution clarification
Fix #125, close #127
1 parent 4e1f7dc commit 5e3b62f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

content/docs/searching.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,9 @@ Anchors match a zero-length position in the line, rather than a particular chara
478478

479479
* `(?<name>`_subset_`)` or `(?'name'`_subset_`)` or `(?(name)`_subset_`)`_Named Capture Group_: Names the value matched by _subset_ as group _name_. Please note that group names are case-sensitive.
480480

481-
* `\ℕ`, `\gℕ`, `\g{ℕ}`, `\g<ℕ>`, `\g'ℕ'`, `\kℕ`, `\k{ℕ}`, `\k<ℕ>` or `\k'ℕ'`_Numbered Backreference:_ These syntaxes match the ℕth capture group earlier in the same expression.
482-
A regex can have multiple subgroups, so `\2`, `\3`, etc can be used to match others (numbers advance left to right with the opening parenthesis of the group). You can have as many capture groups as you need, and are not limited to only 9 groups (though some of the syntax variants can only reference groups 1-9; see the notes below, and use the syntaxes that explicitly allow multi-digit ℕ if you have more than 9 groups)
481+
* `\ℕ`, `\gℕ`, `\g{ℕ}`, `\g<ℕ>`, `\g'ℕ'`, `\kℕ`, `\k{ℕ}`, `\k<ℕ>` or `\k'ℕ'`_Numbered Backreference:_ These syntaxes match the ℕth capture group earlier in the same expression. (Backreferences are used to refer to the capture group contents only in the search/match expression; see the [Substitution Escape Sequences](#substitution-escape-sequences) for how to refer to capture groups in substitutions/replacements.)
482+
483+
A regex can have multiple subgroups, so `\2`, `\3`, etc can be used to match others (numbers advance left to right with the opening parenthesis of the group). You can have as many capture groups as you need, and are not limited to only 9 groups (though some of the syntax variants can only reference groups 1-9; see the notes below, and use the syntaxes that explicitly allow multi-digit ℕ if you have more than 9 groups)
483484

484485
* Example: `([Cc][Aa][Ss][Ee]).*\1` would match a line such as `Case matches Case` but not `Case doesn't match cASE`.
485486

@@ -682,9 +683,11 @@ In substitutions, in addition to allowing the [Control Characters](#control-char
682683

683684
* `$ℕ`, `${ℕ}`, `\ℕ` ⇒ Returns what matched the ℕth subexpression (numbered capture group), where ℕ is a positive integer (1 or larger). If ℕ is greater than 9, use `${ℕ}`.
684685

686+
* Please note: the `\g...` and `\k...` [backreference](#capture-groups-and-backreferences) syntaxes only work in the search expression, and are _not_ designed or intended to work in the substititution/replacement expression.
687+
685688
* `$+{name}` ⇒ Returns what matched subexpression named _name_ (named capture group).
686689

687-
If not described above, `\` followed by any character will output that literal character.
690+
If not described in this section, `\` followed by any character will output that literal character.
688691

689692
#### Substitution Grouping
690693

0 commit comments

Comments
 (0)