Fable icon indicating copy to clipboard operation
Fable copied to clipboard

[Python] Regex lookbehind

Open HLWeil opened this issue 4 months ago • 0 comments

Description

Using lookbehind patterns in regex fails for python.

Repro code

open System.Text.RegularExpressions

let positiveLookbehind = """(?<=A).*"""

Regex(positiveLookbehind)

let negativeLookbehind = """(?<!A).*"""

Regex(negativeLookbehind)

Transpile to python and run.

Expected and actual results

Regex should be created, but fails with:

Traceback (most recent call last):
  File "C:\Users\HLWei\Downloads\FableTesting\output\abc_.py", line 5, in <module>
    create(positive_lookbehind)
  ...
re.error: missing >, unterminated name at position 4

This is caused by the following code in Fable reg_exp.py:

image

Which was probably originally added because of the different Regex syntax for grouping constructs.

Related information

  • Fable version: 4.22.0
  • Operating system: Windows 11

HLWeil avatar Oct 02 '24 13:10 HLWeil