Merge pull request !337 from Almark Ming/master
commit
1bdffc1e56
|
@ -26,12 +26,21 @@ public class RegexSelector implements Selector {
|
||||||
if (StringUtils.isBlank(regexStr)) {
|
if (StringUtils.isBlank(regexStr)) {
|
||||||
throw new IllegalArgumentException("regex must not be empty");
|
throw new IllegalArgumentException("regex must not be empty");
|
||||||
}
|
}
|
||||||
|
/* Can't detect '\(', '(?:)' so that would result in ArrayIndexOutOfBoundsException
|
||||||
if (!StringUtils.contains(regexStr, "(") && !StringUtils.contains(regexStr, ")")) {
|
if (!StringUtils.contains(regexStr, "(") && !StringUtils.contains(regexStr, ")")) {
|
||||||
regexStr = "(" + regexStr + ")";
|
regexStr = "(" + regexStr + ")";
|
||||||
}
|
}
|
||||||
if (!StringUtils.contains(regexStr, "(") || !StringUtils.contains(regexStr, ")")) {
|
if (!StringUtils.contains(regexStr, "(") || !StringUtils.contains(regexStr, ")")) {
|
||||||
throw new IllegalArgumentException("regex must have capture group 1");
|
throw new IllegalArgumentException("regex must have capture group 1");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Try to fix: Only check if there exists the valid left parenthesis, leave regexp validation for Pattern
|
||||||
|
if (StringUtils.countMatches(regexStr, "(") - StringUtils.countMatches(regexStr, "\\\\\\(") ==
|
||||||
|
StringUtils.countMatches(regexStr, "(?:") - StringUtils.countMatches(regexStr, "\\\\\\(?:")) {
|
||||||
|
regexStr = "(" + regexStr + ")";
|
||||||
|
}
|
||||||
|
|
||||||
this.regexStr = regexStr;
|
this.regexStr = regexStr;
|
||||||
try {
|
try {
|
||||||
regex = Pattern.compile(regexStr, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
|
regex = Pattern.compile(regexStr, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
|
||||||
|
|
Loading…
Reference in New Issue