Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Stack overflows when alternation is used in the Java regular expression

User_WA972Apr 11 2022 — edited Apr 11 2022

use of large input string causes the stack overflow, when the characters to be matched are added in alternation
input = "xyxyxyxy...";
regExpression = (x|y)*;
input.matches(regExpression);
Need to know what is the reason for the stack overflow in java? Found one related article that Java regular expression uses recursive calls to implement backtracking.
https://rules.sonarsource.com/java/tag/regex/RSPEC-5998
This gets resolved, when atomic group is created like
regExpression = (**?>**x|y)*
or
[xy]*
or
(x|y)*+

Comments

Post Details

Added on Apr 11 2022
0 comments
678 views