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

(?R) doesn't seem to meet expectations #240

Closed
JetXujing opened this issue Apr 24, 2023 · 2 comments
Closed

(?R) doesn't seem to meet expectations #240

JetXujing opened this issue Apr 24, 2023 · 2 comments

Comments

@JetXujing
Copy link
Contributor

JetXujing commented Apr 24, 2023

[root@localhost ~]# cat re
/(a(?R)b)/
    aabb
[root@localhost ~]# pcre2test re
PCRE2 version 10.39 2021-10-29
/(a(?R)b)/
    aabb
No match
[root@localhost ~]#

I tested it at 10.39 and I don't have the latest version of pcre2, maybe the latest version has fixed it.. From what I understand, this should match.

As I understand it, the regular expression /(a(?R)b)/ means matching a nested string that starts with a and ends with b, and can have a and b in between. For the string aabb, it conforms to the above description because it can be decomposed into two substrings a and abb, where the second substring contains a nested substring ab, and therefore the matching succeeds.

@zherczeg
Copy link
Collaborator

https://regex101.com/r/FbLcN6/1
I don't think your pattern matches anything. The (?R) creates an infinite loop.

Just add a terminating "empty" match: /(a(?:(?R)|)b)/

@JetXujing
Copy link
Contributor Author

https://regex101.com/r/FbLcN6/1
Thank you for your prompt reply. This tool is great and helps me understand the matching process.
And this seems to be an issue with my use, (?R) needs an end judgement

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

No branches or pull requests

2 participants