Dave Siegel
Dave Siegel

Reputation: 203

Regexp to match words in a string, while also matching strings between quotes

I'm having trouble figuring this out. I'll admit i suck at regex, but here's the basic idea:

Let's say you have the string

word "two words" word2

How would i get a regex together to match 'word' and 'word2', and at the same time match 'two words' as it's own match?

Upvotes: 0

Views: 48

Answers (1)

Dekel
Dekel

Reputation: 62676

You can use something like this:

((\w+)|"([ \w]+)")

Here is a regex101:
https://regex101.com/r/eT7CdJ/1

Upvotes: 2

Related Questions