Skip to content

Latest commit

 

History

History
45 lines (30 loc) · 778 Bytes

differences-in-engines.md

File metadata and controls

45 lines (30 loc) · 778 Bytes

Differences In Engines

Different regex engines behave in different ways.

Example 1

Behaviors for unmatched capturing groups differ. In JS, a backreference to an unmatched capturing groups is equivalent to the empty string (epsilon), but in Python it's equivalent to the empty set (as in, reject all).

JS

$ /^(?:(a)|b)\1$/.test("b")
true

Python

$ re.match(r"^(?:(a)|b)\1$", "b") is not None
False

Example 2

This behaves differently because the captured text is reset in JS but not in Python.

JS

$ /^(?:(a)|\1\1){2}$/.test("a")
true

$ /^(?:(a)|\1\1){2}$/.test("aaa")
false

Python

$ re.match(r"^(?:(a)|\1\1){2}$", "a") is not None
False

$ re.match(r"^(?:(a)|\1\1){2}$", "aaa") is not None
True