Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backreferences #24

Open
SonOfLilit opened this issue Sep 1, 2022 · 1 comment
Open

Backreferences #24

SonOfLilit opened this issue Sep 1, 2022 · 1 comment

Comments

@SonOfLilit
Copy link
Owner

SonOfLilit commented Sep 1, 2022

[#start_line [ | '1' | [capture 1+ '11'] [1+ #repeat:1] ] #end_line]

Should compile to:

^(?:1?|(11+?)\1+)$

(which is a slight rephrasing of https://stackoverflow.com/questions/3296050/how-does-this-regex-find-primes)

[#start_line [ | '1' | [capture:factor 1+ '11'] [1+ #repeat:factor] ] #end_line]

Should compile to the same:

^(?:1?|(?P<factor>11+?)\1+)$

(because named backreferences aren't available in regex)

[capture #token][#repeat:0]1

Should compile to:

(\w*)(?:\1)1

(Wrapping required to disambiguate "\1 and then 1" from \11)

See e.g. https://learnbyexample.github.io/py_regular_expressions/groupings-and-backreferences.html

@SonOfLilit
Copy link
Owner Author

Python is done, Rust still needs doing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant