To make the .+
optional, you could do:
\"(?:.+)?\";
(?:..)
is called a non-capturing group. It only does the matching operation and it won’t capture anything. Adding ?
after the non-capturing group makes the whole non-capturing group optional.
Alternatively, you could do:
\".*?\";
.*
would match any character zero or more times greedily. Adding ?
after the *
forces the regex engine to do a shortest possible match.