Windows 11 & Powershell 7.2.5: I'm trying to pass a regular expression in a parameter to my node.js app. The expression, ^@Test, contains a ^ character, which is apparently also used to denote escape sequences in Powershell. Let's say this is my app:
const param = process.argv[2];
console.log(param);
When I run it this way:
node index.js "^@Test"
it works correctly and prints ^@Test
But if I configure a script in package.json like this:
"scripts": {
"start": "node index.js"
}
And I run:
npm run start "^@Test"
the leading ^ gets trimmed and it prints only @Test
Curiously, it does not get trimmed if ^ character is surrounded by a space on either side. So the following work correctly:
npm run start "^ @Test" // prints "^ @Test", correct
npm run start " ^@Test" // prints " ^@Test", correct
npm run start " ^ @Test" // prints " ^ @Test", correct
I tried escaping with ^^, `^ or ^, but neither works:
npm run start "^^@Test" // prints "@Test"
npm run start "`^@Test" // prints "@Test"
npm run start "\^@Test" // prints "\\@Test"
This also does not make a difference:
npm run start -- "^@Test" // prints "@Test"
With different quotes and without quotes it also does not work:
npm run start ^@Test // prints "@Test"
npm run start '^@Test' // prints "@Test"
Is this a bug or am I escaping it wrong?