<?php $contents = <<<EOL console.log('hello'); //# sourceMappingURL= EOL; $backtrack_limit = (int) ini_get('pcre.backtrack_limit'); // Actual limit seems to be this value divided by 2. $backtrack_limit = ($backtrack_limit / 2) - 1; $contents .= str_repeat('x', $backtrack_limit); // Add an empty space after the sourcemap, followed by other code. $contents .= <<<EOL // I appear after the sourcemap. var newcode = 123; EOL; $results = [ 'orig' => preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=\s*(\S*?)\s*$/m', '', $contents), 'proposed' => preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=\s*[^$\s]*\s*$/m', '', $contents), 'alt1' => preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=.*\s*$/m', '', $contents), 'alt2' => preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=\s*[^$\s]*/m', '', $contents), // Most efficient so far based off https://regex101.com - (https://stackoverflow.com/a/36629670). 'alt3' => preg_replace('~//[#@]\s(source(?:Mapping)?URL)=\s*(\S+)~', '', $contents), ]; foreach ($results as $key => $result) { echo "------------------------------------------\n"; echo "Results for '$key':\n"; var_dump($result); }
You have javascript disabled. You will not be able to edit any code.