Improve code of getStringResultFromRegexArray methods in Utils
This commit is contained in:
parent
2e3da445e6
commit
6d27996ac4
1 changed files with 10 additions and 16 deletions
|
@ -391,23 +391,20 @@ public final class Utils {
|
||||||
@Nonnull final String[] regexes,
|
@Nonnull final String[] regexes,
|
||||||
final int group)
|
final int group)
|
||||||
throws Parser.RegexException {
|
throws Parser.RegexException {
|
||||||
String result = null;
|
|
||||||
for (final String regex : regexes) {
|
for (final String regex : regexes) {
|
||||||
try {
|
try {
|
||||||
result = Parser.matchGroup(regex, input, group);
|
final String result = Parser.matchGroup(regex, input, group);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
// Continue if the result is null
|
return result;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Continue if the result is null
|
||||||
} catch (final Parser.RegexException ignored) {
|
} catch (final Parser.RegexException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == null) {
|
|
||||||
throw new Parser.RegexException("No regex matched the input on group " + group);
|
throw new Parser.RegexException("No regex matched the input on group " + group);
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the result of an array of {@link Pattern}s inside an input on a specific
|
* Find the result of an array of {@link Pattern}s inside an input on a specific
|
||||||
|
@ -425,21 +422,18 @@ public final class Utils {
|
||||||
@Nonnull final Pattern[] regexes,
|
@Nonnull final Pattern[] regexes,
|
||||||
final int group)
|
final int group)
|
||||||
throws Parser.RegexException {
|
throws Parser.RegexException {
|
||||||
String result = null;
|
|
||||||
for (final Pattern regex : regexes) {
|
for (final Pattern regex : regexes) {
|
||||||
try {
|
try {
|
||||||
result = Parser.matchGroup(regex, input, group);
|
final String result = Parser.matchGroup(regex, input, group);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
// Continue if the result is null
|
return result;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Continue if the result is null
|
||||||
} catch (final Parser.RegexException ignored) {
|
} catch (final Parser.RegexException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == null) {
|
|
||||||
throw new Parser.RegexException("No regex matched the input on group " + group);
|
throw new Parser.RegexException("No regex matched the input on group " + group);
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue