How to extract a substring using regex

前端 未结 14 1458
暖寄归人
暖寄归人 2020-11-22 13:37

I have a string that has two single quotes in it, the \' character. In between the single quotes is the data I want.

How can I write a regex to extract

14条回答
  •  不要未来只要你来
    2020-11-22 14:32

    There's a simple one-liner for this:

    String target = myData.replaceAll("[^']*(?:'(.*?)')?.*", "$1");
    

    By making the matching group optional, this also caters for quotes not being found by returning a blank in that case.

    See live demo.

提交回复
热议问题