Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

java - PatternSyntaxException using apache poi

I am using Apache POI in two different projects

The first project is a standalone Java application. Everything is fine here.

The second project is an Android project. I can access the Workbook of an xlsx 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 code line in question:

    final Pattern nonAlphabeticPattern = Pattern.compile("\P{IsL}");

Why does Android not accept this? As I said: It's working fine on a standalone Java application ....

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Android is using ICU regex library that is a bit different from Java regex engine.

See this reference:

Unicode scripts, blocks, categories and binary properties are written with the p and P constructs as in Perl. p{prop} matches if the input has the property prop, while P{prop} does not match if the input has that property.

Thus, the pattern should be written as

Pattern nonAlphabeticPattern = Pattern.compile("\P{L}"); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...