Creeper9207 Creeper9207 - 5 months ago 10
PHP Question

PHP regex to match quotes with nothing in them

Here is what i need:

"hello" "" "other"


I want this string to return (in no specific order)

[0] => "hello"
[1] => ""
[2] => "other"

Answer

You can do it like:

"([^"]*)"

Here the captured groups will contain whatever present within the double quotes. So the first captured group will have hello, second nothing and third other.

Demo


If you need to match the quotes too:

("[^"]*")

Demo

Comments