Reputation: 87
I'm looking for a regular expression that matches "batz"
, but not ""
in this text: bla "" and "batz" foo
/"([^"]*)"/g
matches both, /"([^"]+)"/g
matches " and "
.
Is this even possible with regular expressions?
Upvotes: 2
Views: 173
Reputation: 785098
You may use this regex with a captured group:
(?:""|[^"])*("[^"]+")
RegEx Details:
(?:
: Start a non-capture group
""
: Match ""
|
: OR[^"]
: Match any character that is not "
)*
: Close non-capture group. *
lets this group match 0 or more occurrences("[^"]+")
: Match a non-empty double quoted string and capture in group #1Upvotes: 2