What refactoring should I apply on this email validation regex?

52 views Asked by At

Sonarqube is warning me that my Java regex reported down below for email validation should be refactored because "this repetition can lead to a stack overflow for large inputs":

"^(?=.{1,64}@)[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$" Plus, they're emphasizing on this part in particular:

(\\.[A-Za-z0-9-]+)*

It works perfectly fine in my program, it accepts emails with this kind of format:

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

Still, I would like to fix this issue.

I am not able to understand what I should do to fix it tho, is there a way to modify this regex while keeping the same meaning?

0

There are 0 answers