Regular Expression to Split String based on space and matching quotes in java

后端 未结 3 687
一整个雨季
一整个雨季 2021-01-27 18:54

I have a String which i need to split based on the space and the exact matching quotes.

If the

string = \"It is fun \\\"to write\\\" regular\\\"expressi         


        
3条回答
  •  太阳男子
    2021-01-27 19:16

    You are running into a fundamental limitation of regular expressions here. In general they can't detect recursion, depth, etc.

    So in your string:

    "It is fun \"to write\" regular\"expression"
    

    Both the space between to and write and the space between \" and regular are all inside quote marks. Regex is not able to "count" the number of quotes in a flexible way and take action based on it.

    You will need to write your own string parser for this (or use an existing one). Regex can't handle it though.

提交回复
热议问题