0

This is the line which works perfectly fine.

'some words'.split(/,*/);

But when I do a block comment as show below, I get a syntax error.

/* 'some words'.split(/,*/); */

Couldn't find about this behaviour anywhere. Not sure if this is a know bug in the language.

boggy b
  • 31
  • 1
  • 5

2 Answers2

0

The */ in your regex gets parsed as the end of the comment, which is causing the syntax error.

Can you use a single-line comment instead?

// 'some words'.split(/,*/);
Scimonster
  • 32,893
  • 9
  • 77
  • 89
0

This is not a bug in the language, the */ is a known (and deliberate) overlap between regular expression literals and block comment delimiters in the grammar.

You can either use a single-line comment

// 'some words'.split(/,*/);

or change your regex

/* 'some words'.split(/,{0,}/);
'some words'.split(/,*(?:)/); */
Bergi
  • 630,263
  • 148
  • 957
  • 1,375