Answer the question
In order to leave comments, you need to log in
Is it possible to write a regular expression so that it treats quoted strings differently than everything else?
Good evening.
There is a regex that parses a string like this: The regex @param name type value
itself looks like this ( regexr ): $regexp = '/(?![@param*])([\S\-\|]+)/';
Its job is that it splits the string on spaces, ignoring the @param keyword. Now there was a need to be able to write like this: @param name type "Тут может быть любая строка"
Of course, at the moment the quoted string will be broken by space. How can you make sure that any area inside the quotes is treated differently than the rest of the string? It would be cool to add something like (^\"[.]\"$) and get a separate substring group, but that doesn't work.
I would be grateful for advice, thanks.
Answer the question
In order to leave comments, you need to log in
(?![@param*])((?:"[^"]+")|(?:[\S]+))
Or like this, so that you can escape the quotes:
(?![@param*])((?:"(?:(?:\\")|(?:[^"]))+")|(?:[\S]+))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question