I want to match the start of a shell command using the $ character, but my regexp fails.
This is the regexp I want to use: ^s*$s
.
It should match when:
- There are only spaces (or tabs) before the $ character
- There is a space after the $ character
const lineCommandRegexp = new RegExp("s*$")
console.log(
lineCommandRegexp.test("$ the command"),
lineCommandRegexp.test(" $ the command"),
lineCommandRegexp.test("$"),
)
The RegExp in the code above is working, but incomplete. When any other part of the regular expression is added it returns false. Mind you only the first two tests should succeed. I also tested with the global flag, but I think that makes no different in this example.
I usually run some simple tests on regexr.com, and here the regex that I want works as expected.