I am making a stylelint configuration file (uses javascript). We use strings for regular expressions.
I have
[“^([a-z][a-zA-Z0-9]+)|(abc-+(.+))$”,{“message":"(selector) => Expected class selector "${selector}" to be lowerCamelCase or begin with abc"}]
as a parameter of a rule. It is supposed to make sure a variable is in lowerCamelCase or that it starts with abc- and continues on after that.
My concern is with the matching part. It works in regexr (after removing beginning . that is actually accounted for with ^ in the javascript code) (test cases reflect usage)
regexr parameter is successful at testing use cases
I also tested regexr with removing the ^ and results were the same. I did have to use many grouping parantheses and I think this is where the problems arise in javascript.
The error I receive is
stderr: List(SyntaxError: Invalid regular expression: /[“^([a-z][a-zA-Z0-9]+)|(abc-+(.+))$”,{“message":"(selector) => Expected class selector "${selector}" to be lowerCamelCase or begin with abc"}]/: Unmatched ')', at new RegExp (<anonymous>)
I see a lot about unmatched paranthesis errors coming up when they are supposed to be string literals. My problem is that it’s NOT supposed to be a string literal, just a grouping tool. I don’t want to escape it, and I can’t remove any.
I already removed a set of parantheses around the whole thing (which I was already iffy about, since that $ end character needs to apply to both sides of the “or” set) when the unmatched paranthesis error first came up. I know that there are no frivolous parantheses here.