Skip to content
Myr

doc: clarify half-boundary syntax for the `-w/--word-regexp` flag

Before adoption: this commit came in with the history the project adopted, so no landing records it.

In regex 1.10.0, the \b{start-half} and \b{end-half} assertions were introduced to improve how the -w/--word-regexp flag handles patterns containing non-word characters. While ripgrep's CLI help text was updated to mention this syntax during the lexopt transition (082245d), it omitted the rationale, potentially leaving users puzzled by this casual mention of a highly specific, non-standard regex feature. Furthermore, GUIDE.md was still outdated, incorrectly claiming that -w wraps patterns in standard \b boundaries, further compounding the inconsistency and potential for confusion. This commit updates GUIDE.md to reflect the actual underlying regex employed by ripgrep when the -w/--word-regexp flag is used. It also adds a brief explanation to both the guide and the manpage acknowledging the non-standard nature of these half-boundary markers, and explaining what they're meant for. PR #3279

authored by Waldir Pimenta · committed by GitHub · parent cb66736 · Browse files · 2 files+11 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−3 removed

  • other:+11 added−3 removed

2 files+11 added−3 removed

modified:crates/core/flags/defs.rs+6 added-2 removed
7533 unmodified lines
7534 }7535 fn doc_long(&self) -> &'static str {7536 r"7537When enabled, ripgrep will only show matches surrounded by word boundaries.7538This is equivalent to surrounding every pattern with \fB\\b{start-half}\fP7539and \fB\\b{end-half}\fP.7538This is equivalent to surrounding every pattern with \fB\\b{start-half}\fP and7539\fB\\b{end-half}\fP. These are a custom syntax from ripgrep's default regex7540engine that, unlike \fB\\b\fP, doesn't require matching a word character on one7541side. That is, \fB\\b{start-half}\fP corresponds to matching \fB\\W|\\A\fP on7542the left and \fB\\b{end-half}\fP corresponds to matching \fB\\W|\\z\fP on the7543right.7544.sp7545This overrides the \flag{line-regexp} flag.7546"7547 }
232 unmodified lines
modified:GUIDE.md+5 added-1 removed
1002 unmodified lines
1003* `-F/--fixed-strings`: Disable regular expression matching and treat the pattern1004 as a literal string.1005* `-w/--word-regexp`: Require that all matches of the pattern be surrounded1006 by word boundaries. That is, given `pattern`, the `--word-regexp` flag will1007 cause ripgrep to behave as if `pattern` were actually `\b(?:pattern)\b`.1007 cause ripgrep to behave as if `pattern` were actually1008 `\b{start-half}(?:pattern)\b{end-half}`.1009 (Unlike `\b`, these half-boundaries don't require a word character on one1010 side. For example, `rg -w -e -2` will match `-2` in `(-2)` but `rg '\b-2\b'`1011 will not.)1012* `-c/--count`: Report a count of total matched lines.1013* `--files`: Print the files that ripgrep *would* search, but don't actually1014 search them.1015* `-a/--text`: Search binary files as if they were plain text.
11 unmodified lines