开发者

Regular Expression to remove pattern from files

I have many .php files which have the pattern of codes - which I want to remove.

e.g.

<?php echo $arrayT["Hello,This text varies. I want to keep this text only."]; ?>
<?=$arrayT["Hello,This another text varies. I want to keep this text only."]; ?>

There are so many PHP files, all files co开发者_运维百科ntains any of above code as part of lines.

I want to remove the parts

<?php echo $arrayT["' and '"]; ?>

but only in case the line contains

<?(php echo |=)$arrayT["Hello,This text varies. I want to keep this text only."]; ?>

full string in code.

I have tried running different formulas thru CLI, but not a single one comes near to achieve it. Also I believe solution to this can be helpful in many situations, but its just that I could not find solution right myself.


You'll need to use back references...In you're regex you can encode the parts that you're matching in parens.... e.g.

If your pattern was /([A-Z]+)([0-9]+)([A-Z]+)/ and you're replacement was \2

AAA123ZZZ -> 123

(See: http://php.net/manual/en/function.preg-replace.php, backrefrences section as there are a few gotchas when it comes to syntax)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜