PHP Regex匹配其他文件中的所有字符串

I have created one regex that can extract all string from PHP files. Example, I have "abc.php", I want to extract all string inside there (including tags " ' ). I make my own regex but some of string didn't match or overmatch.

Note : My intention also same with post here -> PHP: Regex to match the following string samples

But agent-j answers inside that thread also didn't match some of string.

Basically, this is my regex

/[\"|\'][^.\/\"](.*?)[^,\\][\"|\']/

Here the problem in picture..

enter image description here

enter image description here

enter image description here

enter image description here

I also try use agent-j regex, but his regex has problem when matching string in multiple line.

His regex

(['"])((?:\\\1|(?!\1).)+)\1

Problem with this regex

enter image description here

Look like anybody don't solve my problem. I solved this problem myself with help of my friend. So this is the regex that i was looking for.

/([\"\'])(?:(?=(\\\\?))\\2.)*?\\1/s

The easiest way I have ever found to regex match any logic to an entire file has been to use

$something_better = explode(''',$something);

This way you get an array of data that is more easily evaluated. I use this concept every time I want to guarantee I can make the match exactly how I want every time.

What I would do here is to explode and extract the info between single quotes, matching what I wanted from them, and then implode on the single quote. Since you also want the double quotes, you can then explode and repeat the process for double quotes.

In my experience it is very hard to regex all your problems away in one simple statement. It's better to take it in smaller pieces if you can. There will be less room for error.