<?php
function sed(string $re, string $sub): string
{
if (mb_strlen($re, "8bit") < 4 || $re[0] !== "s")
throw new Error("Your syntax is invalid, go drown yourself");
[1 => $re, 2 => $rep, 3 => $mod] = preg_split("|(?<!\\\\){$re[1]}|", $re);
$re = str_replace('@', '\@', $re);
return preg_replace("@$re@$mod", $rep, $sub);
}
echo sed('s/@FOO\/BAR@/waa/i', 'wee/@foo/bar@/woo'), PHP_EOL;
preferences:
48.69 ms | 402 KiB | 5 Q