Reputation: 35
I found this regular expression in an old system i'm working on.
(\s*)*
I'm pretty sure the extra " * " at the end is redundant but I want to make sure is not doing anything before I remove it. It's causing a performance issue when it's used in the regex.matches() method to the point that hangs the entire system if the string used as a parameter has 25+ spaces
Does anybody knows if that particular syntax has a special functionality?
Ps: Its a pretty huge system so I can't test every posible scenario
Upvotes: 2
Views: 272
Reputation: 34556
Assuming the inner *
is greedy, then, yes, I think the outer one is redundant. The outer *
attempts to repeat the sub-match, but there would only ever be one instance of the sub-match because it's greedy.
Upvotes: 1
Reputation: 38183
It is redundant. You can just use multiple matches to capture 0 or more groups of spaces, which is what the extra asterisk is specifying.
Upvotes: 1