php - Find string inside single and double quotation marks using regex -
how find string between ""
, ''
using regex. want create function using php preg_match_all()
function match static strings in file, creating string using ""
, ''
need find such strings file.
you should aware inside quoted "entities" may find escaped quotes. best way match strings using regex this:
(?s)'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"
see demo
sample code:
$re = "/(?s)'(?:[^'\\\\]|\\\\.)*'|\"(?:[^\"\\\\]|\\\\.)*\"/"; $str = "\"string 'c' \" string \" \" , ' string \"ste\" \' '"; preg_match_all($re, $str, $matches);
Comments
Post a Comment