Reputation: 109
Text is
lemma A:
"
abx K() bc
"
// comment lemma B
lemma B:
"
abx bc sdsf
"
lemma C:
"
abfdfx K() bc
"
lemma D:
"
abxsf bc
"
I want to find the lemmas which contain K() inside its following quoted text. I have tried Perl regex (?s)^[ ]*lemma.*?"(?!").*?K\(
but it overlaps two lemmas. The output should be: lemma A: "..."
and lemma C: "..."
.
Upvotes: 2
Views: 52
Reputation: 163277
If the double quotes are at the start of the string, you can match a newline and then the double quote.
Then match any char except the double quote until you match K(
^[ ]*lemma\b.*\R"[^"]*K\(
^
Start of string[ ]*lemma\b
Match optional spaces and lemma
.*\R
Match the rest of the line and a newline"[^"]*
Match "
followed by optional chars other than "
K\(
Match K(
Upvotes: 1