.*
will lead to errors for strings like This is a "test" string with multiple " in place"
. ".*"
would match the substring "test" string with multiple " in place"
while "[^"]*"
and ".*?"
would only match "test"
. This is because *
is a greedy quantifier which will try to match as many characters as possible.
Whether to use [^"]*
or .*?
: Doesn't really matter in terms of correctness.