languagetool-org/languagetool · error · UnsupportedPatternRuleException
Regex constructs like '?iu' and '?-i' are not supported: + p
Error message
Regex constructs like '?iu' and '?-i' are not supported: + patternToken
What it means
Search-index guard in getRegexQuery: the token's regex uses inline flag constructs like '?iu' or '?-i', which Lucene's RegexpQuery cannot express, so the regex token cannot be indexed.
Source
Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/index/PatternRuleQueryBuilder.java:233
}
private Term getTermQueryTerm(String str) {
return new Term(searchFieldName, str.toLowerCase());
}
private Term getQueryTerm(String prefix, String str, String suffix) {
return new Term(searchFieldName, prefix.toLowerCase() + str.toLowerCase() + suffix.toLowerCase());
}
private Query getRegexQuery(Term term, String str, PatternToken patternToken) throws UnsupportedPatternRuleException {
try {
if (needsSimplification(str)) {
Term newTerm = new Term(term.field(), simplifyRegex(term.text()));
return new RegexpQuery(newTerm);
}
if (str.contains("?iu") || str.contains("?-i")) {
// Lucene's RegexpQuery doesn't seem to support this
throw new UnsupportedPatternRuleException("Regex constructs like '?iu' and '?-i' are not supported: " + patternToken);
}
return new RegexpQuery(term);
} catch (IllegalArgumentException e) {
// constructs like "\p{Punct}" not supported by Lucene RegExp:
throw new UnsupportedPatternRuleException("Advanced regex like '\\p{Punct}' are not supported: " + patternToken);
}
}
private void checkUnsupportedElement(PatternToken patternPatternToken)
throws UnsupportedPatternRuleException {
if (patternPatternToken.hasOrGroup()) {
// TODO: this is not enough: the first of the tokens in the <or> group will not get into this branch
throw new UnsupportedPatternRuleException("<or> not yet supported.");
}
if (patternPatternToken.isUnified()) {
throw new UnsupportedPatternRuleException("Elements with unified tokens are not supported.");
}
if (patternPatternToken.getString() != null && patternPatternToken.getString().matches("\\\\\\d+")) { // e.g. "\1"View on GitHub (pinned to 2e990059ce)
Solutions
- Remove inline flags from the regex; rely on the index's case handling
- Rewrite case-insensitivity by expanding character classes
- Skip the rule for index-based search
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/index/PatternRuleQueryBuilder.java:233 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/fea6e1d6410a303f.
Report an issue: GitHub.