Get more than 1 quotations in text paragraph in R regex

后端 未结 1 2017
萌比男神i
萌比男神i 2021-01-23 09:00

First: Find the texts that are inside the quotations \"I want everything inside here\".

Second: To extract 1 sentence before quotation.

I would like to achieve t

1条回答
  •  温柔的废话
    2021-01-23 09:31

    Since you just want the last sentence I've cleared the regex for you : result

    Explanation : First you're looking for something that is between quotes. And if there is multiples quotes successively you want them to match as one.

    (\"[^\"]*\"(?: *\"[^\"]*\")*)
    

    Does the trick. Then you want to match the sentence before this group. A sentence is starting with a CAPITAL letter. So we will start the match to the first capital encounter before the previously defined group (ie : not followed by any other CAPITAL letter)

    ([A-Z](?:[a-z0-9\W\s])*)
    

    Put it togeither and you obtain :

    ([A-Z](?:[a-z0-9\W\s])*)(\"[^\"]*\"(?: *\"[^\"]*\")*)
    

    0 讨论(0)
提交回复
热议问题