简体   繁体   中英

android regex odd behavior

What is the error with the following regular expression? It is working fine in Java whereas android throws "Pattern Syntax Exception".

         "((?<==)+(\"[^\"]+\"|[^,=+<>#;\r\n]+))"

Avinash Raj pointed to the most important mistake: the + multiplier after positive lookbehind expression.

Using nested marking groups is another mistake. The outer parentheses are useless here and should be removed to reduce complexity.

And backslashes in strings must be escaped with backslashes. As I think that \\r and \\n should be passed to the regular expression engine and not the characters with code value 13 and 10, the string to use is

"(?<==)(\"[^\"]+\"|[^,=+<>#;\\r\\n]+)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM