Concatenate multiple strings in regex if seperated by nothing or whitespace

613 Views Asked by At

I'm new to regex and I'm currently running into an issue when matching multiple consecutive strings.

I want to match strings: "this is a string". I managed to do that.

However, I would also like to match multiple strings if they are concatenated or separated by only whitespace: "this""is a string", or "this" "is" "one string".

The problem I'm having is that if I try to do that I also match "this" as "a string" (note the matched as this should be two separate strings).

I'm using flexc++ so I cannot use more fancy regex stuff like lookahead.

Currently I defined a string as (i used multiple different definitions this one seems the simplest):

string      \"(.*?)\"

and then try to match multiples using:

{string}[ \t]*{string}* 
1

There are 1 best solutions below

2
kishkin On BEST ANSWER

This should work \"[^\"]*\"([ \t]*\"[^\"]*\")*

Or if give a string definition:

string          \"[^\"]*\"
concat_strings  {string}([ \t]*{string})*