How to extract a substring using regex

前端 未结 14 1438
暖寄归人
暖寄归人 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:28

    Because you also ticked Scala, a solution without regex which easily deals with multiple quoted strings:

    val text = "some string with 'the data i want' inside 'and even more data'"
    text.split("'").zipWithIndex.filter(_._2 % 2 != 0).map(_._1)
    
    res: Array[java.lang.String] = Array(the data i want, and even more data)
    

提交回复
热议问题