Skip to content

Commit a631d7b

Browse files
committed
expr: Handle caret '^' at the beginning of an alternative pattern
1 parent fae62ee commit a631d7b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/uu/expr/src/syntax_tree.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ impl StringOp {
174174
'^' => match (prev, prev_is_escaped) {
175175
// Start of a capturing group
176176
('(', true) => re_string.push(curr),
177+
// Start of an alternative pattern
178+
('|', true) => re_string.push(curr),
177179
// Character class negation "[^a]"
178180
('[', false) => re_string.push(curr),
179181
// Explicitly escaped caret

tests/by-util/test_expr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ fn test_regex() {
282282
.args(&["a^b", ":", "a\\^b"])
283283
.succeeds()
284284
.stdout_only("3\n");
285+
new_ucmd!()
286+
.args(&["b", ":", "a\\|^b"])
287+
.succeeds()
288+
.stdout_only("1\n");
285289
new_ucmd!()
286290
.args(&["a$b", ":", "a\\$b"])
287291
.succeeds()

0 commit comments

Comments
 (0)