user2273693
user2273693

Reputation: 1

Regular Expression for extracting strings in quotes (under certain requirements)

maybe the problems seems bathetic, but at the moment I have a real problem in extracting strings from quotes, but fulfilling certain criteria. These are

All my experiments failed. The best guess of mine was:

    (?<=(?<!\\)").*?(?=(?<!\\)")

The problem of it is that if there are no quotes at all, the extracted string is empty.

Thanks a lot for the help
Best regards
cerebro

Upvotes: 0

Views: 129

Answers (1)

anubhava
anubhava

Reputation: 786091

For the test cases written in your question following regex should work for you:

^([^"\n\\]*)(?:\\(")|"|)([^"\n\\]*)(?:\\(")|"|)(.*)$

You need to concatenate group # 1, 2, 3, 4, 5 to get your captured string.

Live Demo: http://www.rubular.com/r/u6m08cRo1v

Upvotes: 1

Related Questions