$re = '/^([ \t]*)import [*] as (\w+) from (?:([\'])((?:(?:\.)+|[^\n\r\'\\\\]+)+)[\']|(["])((?:(?:\.)+|[^\n\r\'\\\\]+)+)["])/m';
$str = 'import * as Atblock from "./atblock"
import * as Atrule from "./atrule"
import * as Supports from "./supports"
import * as Node from \'./node\';
import * as Root from \'./root\'
import Null from \'./null\'
import * as Each from \'./each\'
import * as If from \'./if\'
import * as Call from \'./call\'
import * as UnaryOp from \'./unaryop\'
import * as BinOp from \'./binop\'
import * as Ternary from \'./ternary\'
import * as Block from \'./block\'
import * as Unit from \'./unit\'
import * as String from \'./string\'
import * as HSLA from \'./hsla\'
import * as RGBA from \'./rgba\'
import * as Ident from \'./ident\'
import * as Group from \'./group\'
import * as Literal from \'./literal\'
import * as Boolean from \'./boolean\'
import * as Return from \'./return\'
import * as Media from \'./media\'
import * as QueryList from \'./query-list\'
import * as Query from \'./query\'
import * as Feature from \'./feature\'
import * as Params from \'./params\'
import * as Comment from \'./comment\'
import * as Keyframes from \'./keyframes\'
import * as Member from \'./member\'
import * as Charset from \'./charset\'
import * as Namespace from \'./namespace\'
import * as Import from \'./import\'
import * as Extend from \'./extend\'
import * as Object from \'./object\'
import * as Function from \'./function\'
import * as Property from \'./property\'
import * as Selector from \'./selector\'
import * as Expression from \'./expression\'
import * as Arguments from \'./arguments\'
import * as Atblock from \'./atblock\'
import * as Atrule from \'./atrule\'
import * as Supports from \'./supports\'
';
$subst = "$1import $2 from $3$5$6$4$3$5";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php