0
我有一個Java正則表達式Pattern
由字符串末尾的任何字符組成的一組正面後視。當我在Android之外使用1.6 JDK時編譯並運行得很好,但是當我將它放入我的Android應用代碼時,它會拋出一個PatternSyntaxException
。這是該行:爲什麼我在Android程序中出現PatternSyntaxException?
Pattern namePat = Pattern.compile("(?<=DISCOVERY,\\d,[0-9A-F]{12},\\d,[+-][\\d]{3},\\d,[\\d]{4})(.*)$");
,這裏是錯誤消息:
4784:D/com.example.MyTestApp.DiscoverThread(4255): java.util.regex.PatternSyntaxException: Look-behind pattern matches must have a bounded maximum length near index 56:
4785:D/com.example.MyTestApp.DiscoverThread(4255): (?<=DISCOVERY,\d,[0-9A-F]{12},\d,[+-][\d]{3},\d,[\d]{4})(.*)$
4786:D/com.example.MyTestApp.DiscoverThread(4255): ^
4787:D/com.example.MyTestApp.DiscoverThread(4255): at java.util.regex.Pattern.compileImpl(Native Method)
4788:D/com.example.MyTestApp.DiscoverThread(4255): at java.util.regex.Pattern.compile(Pattern.java:411)
4789:D/com.example.MyTestApp.DiscoverThread(4255): at java.util.regex.Pattern.<init>(Pattern.java:394)
4790:D/com.example.MyTestApp.DiscoverThread(4255): at java.util.regex.Pattern.compile(Pattern.java:381)
4791:D/com.example.MyTestApp.DiscoverThread(4255): at com.example.MyTestApp.Parser$DiscoveryParser.<init>(Parser.java:146)
4792:D/com.example.MyTestApp.DiscoverThread(4255): at com.example.MyTestApp.DiscoverThread.run(DiscoverThread.java:61)
4793:D/com.example.MyTestApp.DiscoverThread(4255): at java.lang.Thread.run(Thread.java:841)
據我所知,外觀,背後是完全指定的長度。我錯過了什麼嗎?該應用程序在Android 4.4.2設備上運行
什麼是你輸入的字符串? – anubhava
它試圖匹配看起來像這樣的「DISCOVERY,6,FCF37E10824A,0,-042,2,1109BlueTooth109A4C」的字符串尾部。這可能不是最有效的正則表達式,但我爲什麼無法編譯我很困惑。 – rvb
這是因爲你的Lookbehind – hwnd