-1

'C12345678'.match("^C\d{8}$") and

'C12345678'.match("^C\[0-9]{8}$")

Why does this statement has different values?

Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130

1 Answers1

0

Because in the first case you need to escape the backslash:

   console.log('C12345678'.match("^C\\d{8}$"));

Edit

As pointed out by Wiktor in the comment below, it's best to use the Regex literal syntax:

    console.log('C12345678'.match(/^C\d{8}$/));
Community
  • 1
  • 1
Cristian Lupascu
  • 39,078
  • 16
  • 100
  • 137
  • 2
    Best is `/^C\d{8}$/` since it is readable, does not require using double backslashes to escape special characters and because the pattern is static. – Wiktor Stribiżew Sep 16 '16 at 09:41