1

In Python, there is a special re.DEBUG flag that would display the regular expression parse tree:

>>> import re
>>>
>>> data = "myid_01234"
>>> re.match(r"^myid_(\d+)$", data, re.DEBUG)
at at_beginning
literal 109
literal 121
literal 105
literal 100
literal 95
subpattern 1
  max_repeat 1 4294967295
    in
      category category_digit
at at_end
<_sre.SRE_Match object at 0x104ffe7b0>

Is it possible to get a similar debug information with a parse tree in JavaScript?

> var re = /^myid_(\d+)$/;
> var data = "myid_01234"
> data.match(re)
["myid_01234", "01234"]
alecxe
  • 441,113
  • 110
  • 1,021
  • 1,148

1 Answers1

4

JavaScript does not offer this.

But you can use an online service or software to debug it. Example: https://regex101.com/r/vY0iK9/1

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Cyrbil
  • 6,250
  • 1
  • 23
  • 38
  • https://www.debuggex.com/ is also a nice tool to manually advance a match attempt – Mariano Sep 23 '15 at 08:03
  • I used debuggex for a long time, the graphing feature is pretty neat. These site have both pretty much the same functionality, so I guess it's a matter of opinion. – Cyrbil Sep 23 '15 at 08:09