How to extract a substring using regex

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

    as in javascript:

    mydata.match(/'([^']+)'/)[1]
    

    the actual regexp is: /'([^']+)'/

    if you use the non greedy modifier (as per another post) it's like this:

    mydata.match(/'(.*?)'/)[1]
    

    it is cleaner.

提交回复
热议问题