我得到一個java.util.regex.PatternSyntaxException
試圖調用string.split() 用正則表達式(?<=}),(?=\\{)
對一個字符串時,如「{測試},{}測試」java.util.regex.PatternSyntaxException在Android
這當我在JVM上的一個單元測試運行它工作正常(即未在Android上。),但在Android上,我得到以下堆棧跟蹤:
java.util.regex.PatternSyntaxException: Syntax error U_REGEX_RULE_SYNTAX near index 5:
(?<=}),(?=\{)
^
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.util.regex.PatternSyntaxException: Syntax error U_REGEX_RULE_SYNTAX near index 5:
(?<=}),(?=\{)
^
at java.util.regex.Pattern.compileImpl(Native Method)
at java.util.regex.Pattern.compile(Pattern.java:400)
at java.util.regex.Pattern.<init>(Pattern.java:383)
at java.util.regex.Pattern.compile(Pattern.java:374)
at java.lang.String.split(String.java:2021)
at java.lang.String.split(String.java:2002)
我想知道如果在Android運行時不支持正則表達式lookaheads,任何人都可以證實這一點或提供解決此問題的任何建議?
您是否嘗試逃避'}'角色? – t00ny 2011-06-16 16:49:51
'}'字符不需要被轉義,如果你嘗試它會使得正則表達式非法。 – 2011-06-17 10:12:24