Regex exclude specific charater

Viewed 40

I'm trying to extract the substring in-between two double quotes if present but I am only able to get the substring with the last double quote.

If the string has no double quotes, extract the substring

TEST STRINGS

"松嶋友里奈/ウェルキッズフォト" <service-info@wel-kids.jp>
SuperBacker Team <no-reply@backermail.com>
Medium Daily Digest <noreply@medium.com>
"Tory @ Flippa" <marketing@flippa.com>
CocaCola <team@cocacola.com>

My regex for python: "(?!\")(.*?)(?!\")(?=\s\<)"

ACTUAL RESULT

松嶋友里奈/ウェルキッズフォト**"** --> FAILED because of the double quote at the end
SuperBacker Team --> PASS
Medium Daily Digest --> PASS
Tory @ Flippa**"** --> FAILED because of the double quote at the end
CocaCola --> PASS

Why does my pattern include the double quote at the end but not at the beginning?

1 Answers

((?<=^)(?=[^\"])|(?<=\")).*[^\"](?=\"?\s\<)

  • ((?<=^)(?=[^\"])|(?<=\")) either beginning of string - not followed by " ((?<=^)(?=[^\"])) or starting after " ((?<=\"))
  • .*[^\"]anything that does not end in a double quote
  • (?=\"?\s\<) followed by optionally a double quote and then <
Related