Java Regex for matching quoted string with escaped quotes

后端 未结 1 1800
心在旅途
心在旅途 2020-12-16 04:17

I know there are already many questions like mine but I found no answer which works in Java. So I write a new question.

I have text files with content like this:

相关标签:
1条回答
  • 2020-12-16 05:00

    Try this regular expression:

    '([^\\']+|\\([btnfr"'\\]|[0-3]?[0-7]{1,2}|u[0-9a-fA-F]{4}))*'|"([^\\"]+|\\([btnfr"'\\]|[0-3]?[0-7]{1,2}|u[0-9a-fA-F]{4}))*"
    

    And as a string literal:

    "'([^\\\\']+|\\\\([btnfr\"'\\\\]|[0-3]?[0-7]{1,2}|u[0-9a-fA-F]{4}))*'|\"([^\\\\\"]+|\\\\([btnfr\"'\\\\]|[0-3]?[0-7]{1,2}|u[0-9a-fA-F]{4}))*\""
    
    0 讨论(0)
提交回复
热议问题