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
  • 462,703
  • 120
  • 1,088
  • 1,195

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,738
  • 21
  • 105
  • 131
Cyrbil
  • 6,341
  • 1
  • 24
  • 40
  • 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