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); 

ideone demo


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -