Understand Regular Expression Backtracking in Chrome V8

192 views
Skip to first unread message

Zeeshan Jan

unread,
Dec 30, 2014, 3:59:05 AM12/30/14
to v8-u...@googlegroups.com
Hi All,
I am trying to learn and understand the regular expressions in javascript and would like to understand the concept of backtracking for regular expressions in javascript. Can anyone point me to the source code or refer me to the algorithm which javascript in Google Chrome (V8 Engine) uses to parse regular expressions and to check how does it backtrack. As Google's V8 Engine is Open Source this must not be difficult.

Ben Noordhuis

unread,
Dec 30, 2014, 10:30:07 AM12/30/14
to v8-u...@googlegroups.com
Backtracking in V8 is implemented using a stack. The relevant files
are in src/*regex*; it's part JS, part C++.

It's worth mentioning that irregexp, the regular expression parser,
normally emits native code but it also has a bytecode interpreter. I
don't think the interpreter is currently used (maybe by the
out-of-tree PPC port) unless you build with v8_interpreted_regexp=1.
Reply all
Reply to author
Forward
0 new messages