I'm developing a regex that matches var, let and const in javascript code except within strings and comments. I managed this:
But this only matches 2 of the test cases. I'm stuck here.
CodePudding user response:
this regex matches any var, let or const which is at the start of a line and only preceded by spaces:
^\s*(var|let|const)
explanation:
^assert is start of line\s*any amount of space characters (zero till n)(var|let|const)match any of the wordsvar,letorconst
downside of this regex, it matches the spaces as well, which might not be desired
