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"]

1 Answer 1

4
+100

JavaScript does not offer this.

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

Sign up to request clarification or add additional context in comments.

2 Comments

debuggex.com is also a nice tool to manually advance a match attempt
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.