w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Regex match whole words between quotes

The simplest solution would be to use two expressions as you suggest. This will extract strings inside double quotes:

/"[^"]+"/g

Then loop through the results of the first expression, passing them to the second to extract only word matches:

/w+/g

Beware though that languages differ greatly in their implementation of word characters. JavaScript for example has very poor support for international characters, but for English, this should be fine. Should you need to support a larger character set, this expression might be a good replacement for the second one, but you will need to do your own testing with the material you are handling:

/[^" ]+/g

If you happen to be working in, say PHP or Java which do support lookbehind/lookahead matching, you might be able to combine the two operations into one expression, but usually those are more error prone and harder to debug. That's why I would recommend going for a split solution.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.