Creeper9207 Creeper9207 - 1 year ago 50
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 Source

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