regexgittypescriptgit-grep

fatal: command line, '\/\/( ){0,}beforeEach\(async\(\(\) => \{$': Unmatched \{


I am looking for the list of files where some tests are commented like

//     beforeEach(async(() => {
//   beforeEach(async(() => {
 //     beforeEach(async(() => {
//    beforeEach(async(() => {

From https://regex101.com/

\/\/( ){0,}beforeEach\(async\(\(\) => \{$

works fine, ... but inside the terminal I got

git grep "\/\/( ){0,}beforeEach\(async\(\(\) => \{$"
fatal: command line, '\/\/( ){0,}beforeEach\(async\(\(\) => \{$': Unmatched \{

Solution

  • You need to make sure the pattern complies with the POSIX BRE standard.

    Use

    git grep "// *beforeEach(async(() => {$"
    

    That is, ( in a POSIX BRE expression matches a literal ( and { matches a literal {.

    When you escape the open brace, \{, it starts a range quantifier, and thus \} is expected and hence is the error, Unmatched \{.