Optimize regex expressions
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-01-15 05:22:22 +01:00
parent ee4c5155fa
commit b55a27fdfb
2 changed files with 5 additions and 2 deletions

View File

@@ -106,8 +106,11 @@ public class FormatUtil
eg: 3d, 33hours, 32048dojg, 3d2h5m22s.
it does not match if the [digits and characters] blocks are missing.
eg: 33, asd, 3g5hj, 4 asd.
{1,10} is used to limit the size of the input to parse, to avoid stack overflows.
no one should be typing more than 10 arguments, or more than 10 digits for a single argument anyway.
*/
if(!duration.matches("(\\d+[a-zA-Z]+)+"))
if(!duration.matches("(\\d{1,10}[a-zA-Z]{1,10}){1,10}"))
return null;
String[] durationTimes = duration.split("[a-zA-Z]+");