Skip to content

Commit e73d9bf

Browse files
committed
feat: replace add --exact option
for consistency with `search` and `searchset`
1 parent ea24be9 commit e73d9bf

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/cmd/replace.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ replace arguments:
2727
replace options:
2828
-i, --ignore-case Case insensitive search. This is equivalent to
2929
prefixing the regex with '(?i)'.
30-
--literal Treat the regex pattern as a literal string. This allows
31-
you to search for exact matches that even contain
32-
regex special characters.
30+
--literal Treat the regex pattern as a literal string. This allows you
31+
to search for matches that contain regex special characters.
32+
--exact Match the ENTIRE field exactly. Treats the pattern
33+
as a literal string (like --literal) and automatically
34+
anchors it to match the complete field value (^pattern$).
3335
-s, --select <arg> Select the columns to search. See 'qsv select -h'
3436
for the full syntax.
3537
-u, --unicode Enable unicode support. When enabled, character classes
@@ -84,6 +86,7 @@ struct Args {
8486
flag_delimiter: Option<Delimiter>,
8587
flag_ignore_case: bool,
8688
flag_literal: bool,
89+
flag_exact: bool,
8790
flag_size_limit: usize,
8891
flag_dfa_size_limit: usize,
8992
flag_not_one: bool,
@@ -104,6 +107,8 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
104107

105108
let arg_pattern = if args.flag_literal {
106109
regex::escape(&args.arg_pattern)
110+
} else if args.flag_exact {
111+
format!("^{}$", regex::escape(&args.arg_pattern))
107112
} else {
108113
args.arg_pattern.clone()
109114
};

0 commit comments

Comments
 (0)