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

Hang when including extra modifiers in some odd cases #13

Open
Col-E opened this issue Nov 28, 2022 · 0 comments
Open

Hang when including extra modifiers in some odd cases #13

Col-E opened this issue Nov 28, 2022 · 0 comments

Comments

@Col-E
Copy link

Col-E commented Nov 28, 2022

I've been looking to make a regex that tells me how many groups (matching) there are in another given regex and found a pattern that looks like this:
image

String pattern = "\\((?!\\?:)[^)(]*+(?:[^)(]*)*+\\)";
String text = "([ \\t]+)(?:\\/\\/[^\\n]*TODO\\b[^\\n]+\\n)(\\/\\/[^\\n]+)?\\n?((\\1)(?2)\\n)*";
Matcher matcher = Pattern.compile(pattern).matcher(text);
matcher.find()

Unfortunately, calling matcher.find() in this case hangs.

Now, if I alter the pattern into \((?!\?:)[^)(]*+(?:[^)(])*+\) I still get the expected matches, and there is no more hang. I know that the behavior of the pattern is technically changed, but I control the input and it still works for all my desired cases. The standard java.util.regex impl seems to handle both cases fine. No biggie since there is a work-around, but any ideas why this hang occurs with the original pattern?

TLDR:
\((?!\?:)[^)(]*+(?:[^)(])*+\) - Works
\((?!\?:)[^)(]*+(?:[^)(]*)*+\) - Hangs, has one additional *

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

1 participant