Skip to content

Commit 7c4a426

Browse files
committed
Add "Backtracking Control Verbs"
1 parent b2b594e commit 7c4a426

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

content/docs/searching.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,19 @@ These special groups consume no characters. Their successful matching counts, bu
870870
- For variable-length lookbehind assertions from a limited set of constant data items, a construct such as `((?<=short)|(?<=longer))` is viable. The individual lookbehinds still cannot include `+` or `*` or similar variable-length syntax.
871871
- If your desired lookbehind is more complicated than that, you can use `\K` (see above): instead of `(?<=a.*b)MATCH`, which won't work, use `a.*b\KMATCH`. The `\K` workaround will only work if the desired lookbehind is the first part of your match, because _everything_ before the `\K` is excluded from the final match.
872872
873+
#### Backtracking Control Verbs
874+
875+
These will control how and when the regular expression will "backtrack" (go back to a previous point in the text and re-try the match with a different alternative or different number of characters consumed by the wildcard).
876+
877+
- `(*PRUNE)` ⇒ Has no effect unless backtracked onto, in which case all the backtracking information prior to this point is discarded.
878+
- `(*SKIP)` ⇒ Behaves the same as `(*PRUNE)` except that it is assumed that no match can possibly occur prior to the current point in the string being searched. This can be used to optimize searches by skipping over chunks of text that have already been determined can not form a match.
879+
- `(*THEN)` ⇒ Has no effect unless backtracked onto, in which case all subsequent alternatives in a group of alternations are discarded.
880+
- `(*COMMIT)` ⇒ Has no effect unless backtracked onto, in which case all subsequent matching/searching attempts are abandoned.
881+
- `(*FAIL)` ⇒ Causes the match to fail unconditionally at this point, can be used to force the engine to backtrack.
882+
- `(*ACCEPT)` ⇒ Causes the pattern to be considered matched at the current point. Any half-open sub-expressions are closed at the current point.
883+
884+
These can be confusing, so [Notepad++ Community Forum](https://community.notepad-plus-plus.org/)-regular `@guy038` has written up detailed [descriptions with examples](https://community.notepad-plus-plus.org/topic/19632/new-backtracking-control-verbs-feature-available-since-notepad-v7-7) of these verbs, and collected references to other resources to study more about them.
885+
873886
### Substitutions
874887
875888
Substitution expressions (the contents of the **Replace with** entry) use similar syntax to the search expression, with the additional features described below.

0 commit comments

Comments
 (0)