简体   繁体   English

Android正则表达式异常行为

[英]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". 它在Java中工作正常,而android则抛出“模式语法异常”。

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

Avinash Raj pointed to the most important mistake: the + multiplier after positive lookbehind expression. Avinash Raj指出了最重要的错误:正向后看表达式后的+乘数。

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应该传递给正则表达式引擎,而不是代码值为13和10的字符,因此使用的字符串是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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