How to divide by space keeping words with spaces inside quotes?
Basile.B
b2.temp at gmx.com
Mon Aug 9 04:19:05 UTC 2021
On Sunday, 8 August 2021 at 23:04:32 UTC, Marcone wrote:
> How to divide by space keeping words with spaces inside quotes?
>
> Exanple:
>
> string text = "Duck Cat \"Carl Rivers\" Dog";
>
> I want split to:
>
> ["Duck", "Cat", "Carl Rivers", "Dog"]
>
>
> ATENTION: I DON'T WANT:
>
> ["Duck", "Cat", "Carl", "Rivers", "Dog"]
>
>
> How can I get it in Dlang?
You can use a regex. Apparently [the
pattern](https://regex101.com/r/cyx0pC/1) `(\"[\w ]*\")|\w*`
would work, other option is to write a dedicated lexer, as
suggested in the other answer.
More information about the Digitalmars-d-learn
mailing list