Max Koretskyi
Max Koretskyi

Reputation: 105497

Is JS regexp engine regex-directed or text-directed

I'm reading about different regexps engines here and there are two types of engines: regex-directed and text-directed. What engine type does JavaScript use? I assume it's regex-directed, but I'd like to know for sure.

Upvotes: 2

Views: 220

Answers (2)

olha
olha

Reputation: 2262

You can do the test by applying the regex «regex|regex not» to the string “regex not”. If the resulting match is only „regex”, the engine is regex-directed. If the result is „regex not”, then it is text-directed. The reason behind this is that the regex-directed engine is “eager”.

A heuristics from Jan Goyvaerts book. Works for Python 3.7 re library.

Upvotes: 0

axelduch
axelduch

Reputation: 10849

In the link you provided, it is said that regex-directed engines only can process backreferences, given that JavaScript regexes have this feature, I'd says it's regex-directed.

Excerpt from the article :

Nearly all modern regex flavors are based on regex-directed engines. This is because certain very useful features, such as lazy quantifiers and backreferences, can only be implemented in regex-directed engines.

Upvotes: 2

Related Questions