Skip to content

Add --regextype=RE2|EXACT: -grep literal vs regex mode (#99) - #213

Merged
helly25 merged 1 commit into
mainfrom
feat/grep-regextype
Jul 2, 2026
Merged

Add --regextype=RE2|EXACT: -grep literal vs regex mode (#99)#213
helly25 merged 1 commit into
mainfrom
feat/grep-regextype

Conversation

@helly25

@helly25 helly25 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

First -grep enhancement (#99), and the answer to your "exact vs regex" requirement: a --regextype global that selects how -grep reads its pattern.

$ xff data -grep '3.50'                 # RE2: '.' is a wildcard
data/p.txt:1:price 3.50
data/p.txt:2:price 3X50
$ xff --regextype=EXACT data -grep '3.50'   # EXACT: literal dot
data/p.txt:1:price 3.50

Wiring: run.cc ResolveGrepLiteral (RE2→false, EXACT→true, MATCH/PCRE/unknown→InvalidArgument refused before the walk) threads EvalContext::grep_literal; EvalGrep branches to a literal StrContains instead of the pre-compiled RE2 matcher, so EXACT never depends on the pattern being a valid regex. -content/-rxc and find's own positional -regextype primary are untouched - per the dash-count convention --regextype is the xff global superset; #85 unifies them.

Self-doc: --regextype in globals.cc + kHelpText; design.md -grep note updated to "shipped RE2|EXACT". Tests: evaluate_test (EXACT literal dot + regex-metachar-as-literal), run_test (EXACT vs RE2 default, reserved value is a usage error), grep_test.sh e2e. bazel test //... green (39).

Next in #99: -grep=FORMAT custom template with {line}/{text} fields.

The first -grep enhancement and the answer to "exact vs regex": a --regextype
global selects how -grep reads its pattern. RE2 (the default) is the regex engine;
EXACT matches the pattern as a literal substring per line (so '.' is a literal dot
and an unparseable-as-regex pattern like 'foo(bar' is a fine literal). The
grep-flavor MATCH and the PCRE engine are reserved for #85 and refused now with a
clear usage error (exit 2), as is any unknown value.

Wiring: run.cc ResolveGrepLiteral (RE2->false, EXACT->true, MATCH/PCRE/unknown->
InvalidArgument, refused before the walk) threads EvalContext::grep_literal;
EvalGrep branches to a literal StrContains matcher instead of the pre-compiled RE2
one, so EXACT never depends on the pattern being a valid regex. -content/-rxc and
find's own -regextype primary are untouched (dash-count convention: --regextype is
the xff global superset; #85 unifies them).

Self-doc: --regextype in globals.cc + kHelpText; design.md -grep note updated to
"shipped RE2|EXACT". Tests: evaluate_test (EXACT literal dot + regex-metachar-as-
literal), run_test (EXACT vs RE2 default, reserved value is a usage error),
grep_test.sh e2e. bazel test //... green (39).
@helly25
helly25 enabled auto-merge (squash) July 2, 2026 22:53
@helly25
helly25 merged commit d6b8d54 into main Jul 2, 2026
8 checks passed
@helly25
helly25 deleted the feat/grep-regextype branch July 2, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant