Java regex content between single quotes

后端 未结 5 1428
臣服心动
臣服心动 2020-12-09 10:37

I am trying to write a regex in Java to find the content between single quotes. Can one please help me with this? I tried the following but it doesn\'t work in some cases:

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 11:10

    If you don't allow the single quote character, ', or the space character, ' ', to be in the pattern, then you're good to go. I used + because I assumed you don't want an empty entry (if not, change it back to an *):

    Pattern p = Pattern.compile("'([^' ]+)'");
    

提交回复
热议问题