Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preg_match check if string is surrounded in double or single quotes

Can someone tell me the regex to see if something is surrounded in double or single quotes.

"this is the string"

i want it to return false if it quotes are not present at all or not present at the start and the end.

like image 241
madphp Avatar asked Oct 24 '25 16:10

madphp


1 Answers

preg_match('/^(["\']).*\1$/m', $string);

will return 1 if the string is surrounded by double quotes and 0 if it is not.

like image 150
Zulan Avatar answered Oct 26 '25 06:10

Zulan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!