As long as there is no quote nesting (nesting in general is something regex is bad at):
"(?:(?<=\\)"|[^"])*"|\*[^\s]+|[^\s]+\*
This regex allows for escaped double quotes ('\"'
), though, if you need that. And the match includes the enclosing double quotes.
This regex matches:
"A string in quotes, possibly containing \"escaped quotes\""
*a_search_word_beginning_with_a_star
a_search_word_ending_with_a_star*
*a_search_word_enclosed_in_stars*
Be aware that it will break at strings like this:
A broken \"string "with the quotes all \"mangled up\""
If you expect (read: can't entirely rule out the possibility) to get these, please don't use regex, but write a small quote-aware parser. For a one-shot search and replace activity or input in a guaranteed format, the regex is okay to use.
For validating/parsing user input, it is not okay to use. That's where I would recommend a parser. Knowing the difference is the key.