TemplateSyntaxException using apache poi
I am using POI Apache in 2 different projects
The first project is a stand-alone Java application. Everything is fine here.
The second project is an Android project. I can access the xlsx workbook just fine, but when it comes to evaluating formulas it crashes with an Exception
java.util.regex.PatternSyntaxException: U_ILLEGAL_ARGUMENT_ERROR \P{IsL}
at java.util.regex.Pattern.compileImpl(Native Method)
at java.util.regex.Pattern.compile(Pattern.java:411)
at java.util.regex.Pattern.<init>(Pattern.java:394)
at java.util.regex.Pattern.compile(Pattern.java:381)
at org.apache.poi.ss.formula.functions.TextFunction$5.<init>(TextFunction.java:124)
at org.apache.poi.ss.formula.functions.TextFunction.<clinit>(TextFunction.java:123)
This is the line of code in question:
final Pattern nonAlphabeticPattern = Pattern.compile("\\P{IsL}");
Why doesn't Android accept this? As I said: it works fine on a standalone Java application ....
source to share
Android uses the ICU regex library, which is slightly different from the Java regex engine.
See this link :
Scripts, blocks, categories, and Unicode binary properties are written in constructs
\p
and\p
like in Perl.\p{prop}
matches if the input has a prop property,\p{prop}
not matches if the input has that property.
Thus, the template should be written as
Pattern nonAlphabeticPattern = Pattern.compile("\\P{L}");
source to share