【发布时间】:2016-11-17 11:42:57
【问题描述】:
我在两个不同的项目中使用 Apache POI
第一个项目是一个独立的 Java 应用程序。这里一切都很好。
第二个项目是一个 Android 项目。我可以很好地访问 xlsx 的工作簿,但是在评估公式时,它会因异常而崩溃
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)
这是有问题的代码行:
final Pattern nonAlphabeticPattern = Pattern.compile("\\P{IsL}");
为什么 Android 不接受这个?正如我所说:它在独立的 Java 应用程序上运行良好....
【问题讨论】:
-
使用
final Pattern nonAlphabeticPattern = Pattern.compile("\\P{L}"); -
\\P{IsL}不是一个完全合法的模式吗?根据甲骨文,它是Categories may be specified with the optional prefix Is: Both \p{L} and \p{IsL} denote the category of Unicode letters. Same as scripts and blocks, categories can also be specified by using the keyword general_category (or its short form gc) as in general_category=Lu or gc=Lu. -
Android 正在使用 ICU 正则表达式库,Java 有自己的基于 ICU 的正则表达式。参见this:Unicode 脚本、块、类别和二进制属性是用
\p和\P结构编写的,就像在Perl 中一样。如果输入具有属性 prop,\p{prop}匹配,而如果输入具有该属性,\P{prop}则不匹配。 -
不要误会我的意思……如果可以的话,我会改变它。它是他们库中 apache poi 代码的一部分
-
你的意思是你不能改变模式?
标签: java android regex apache-poi