diff --git a/brush-parser/src/parser.rs b/brush-parser/src/parser.rs index b5a9d3e7..734d363e 100644 --- a/brush-parser/src/parser.rs +++ b/brush-parser/src/parser.rs @@ -420,7 +420,11 @@ peg::parser! { rule regex_word_piece() = word() {} / specific_operator("|") {} / - specific_operator("(") inner:regex_word() specific_operator(")") {} + specific_operator("(") parenthesized_regex_word()* specific_operator(")") {} + + rule parenthesized_regex_word() = + regex_word_piece() / + !specific_operator(")") !specific_operator("]]") [_] rule name() -> &'input str = w:[Token::Word(_, _)] { w.to_str() } diff --git a/brush-shell/tests/cases/extended_tests.yaml b/brush-shell/tests/cases/extended_tests.yaml index c8e84edf..a7bf1274 100644 --- a/brush-shell/tests/cases/extended_tests.yaml +++ b/brush-shell/tests/cases/extended_tests.yaml @@ -215,6 +215,11 @@ cases: echo "Matches" fi + - name: "Regex with special chars in parens" + stdin: | + [[ "<" =~ (<) ]] && echo "1. Matched" + [[ ">" =~ (<) ]] && echo "2. Matched" + - name: "Empty and space checks" stdin: | check() {