Regex pattern to choose data BETWEEN matching quotation marks

后端 未结 5 916
悲哀的现实
悲哀的现实 2020-12-19 08:59

Suppose I had the following string I wanted to run a Regular expression on:

This is a test string with \"quotation-marks\" within it.
The \"problem\" I am ha         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-19 09:57

    What you need to do is explicitly only match strings inside quotes that have -.

    Use this:

    (\"[^"]*.*?)-(.*?\")
    

    Working example: http://regex101.com/r/jK5eL9

    The only catch here is that it will only work for single instances of word-word in quotes. If you had, say, "word-word, and word-word" it will fail.

提交回复
热议问题