I'm currently writing a code obfuscator for PHP in PHP, just to improve my skills with regex syntax.
The goal is to base64_encode strings before any obfuscating processes, and decode it after any obfuscating processes. On standard strings like "foo bar" or 'foo bar' everything works, but it does not work with string containing escaped (double/simple) quotes like this one : 'return \'"\'.base64_encode($matches[0]).\'"\';'
As you can see, I'm trying to obfuscate my own code, which seems to be fun. But my own code contains specific regex strings, which aren't correctly parsed.
Here is the code in charge of encoding a string starting and ending with simple quotes (the code in charge to do the same thing with double quote is almost the same) :
$this->output = preg_replace_callback('/(?<!\\\\)\'(.*)(?<!\\\\)\'/isU', create_function(
'$matches',
'return "\'".base64_encode($matches[0])."\'";'
), $this->output
);
Any ideas ?
iflag in your pattern is useless because there's nothing in the pattern that has a different representation in the "other" case.