Skip to content

Commit

Permalink
Improve code of getStringResultFromRegexArray methods in Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
AudricV committed Mar 27, 2022
1 parent cef40e3 commit 5f12ac2
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,22 +391,19 @@ public static String getStringResultFromRegexArray(@Nonnull final String input,
@Nonnull final String[] regexes,
final int group)
throws Parser.RegexException {
String result = null;
for (final String regex : regexes) {
try {
result = Parser.matchGroup(regex, input, group);
final String result = Parser.matchGroup(regex, input, group);
if (result != null) {
// Continue if the result is null
break;
return result;
}

// Continue if the result is null
} catch (final Parser.RegexException ignored) {
}
}

if (result == null) {
throw new Parser.RegexException("No regex matched the input on group " + group);
}
return result;
throw new Parser.RegexException("No regex matched the input on group " + group);
}

/**
Expand All @@ -425,21 +422,18 @@ public static String getStringResultFromRegexArray(@Nonnull final String input,
@Nonnull final Pattern[] regexes,
final int group)
throws Parser.RegexException {
String result = null;
for (final Pattern regex : regexes) {
try {
result = Parser.matchGroup(regex, input, group);
final String result = Parser.matchGroup(regex, input, group);
if (result != null) {
// Continue if the result is null
break;
return result;
}

// Continue if the result is null
} catch (final Parser.RegexException ignored) {
}
}

if (result == null) {
throw new Parser.RegexException("No regex matched the input on group " + group);
}
return result;
throw new Parser.RegexException("No regex matched the input on group " + group);
}
}

0 comments on commit 5f12ac2

Please sign in to comment.