2

Apologies in advance for the confusing title. My issue is as follows, I have the following text in about 600 files:

$_REQUEST['FOO']

I would like to replace it with the following:

$this->input->post('FOO')

To clarify, I am matching against the following:

$_REQUEST any number of A-Za-z\d followed by a ]

and replacing it with:

$this->input->post( the alphanumeric word from above followed by a )

Or in general:

Anchor token  TEXT TO KEEP  end anchor token

This differs from standard find/replace as I want to retain text inside of two word boundaries.

Is this functionality present in any text editors (Eclipse,np++,etc). Or am I going to need to write some type of program to parse these 600 files to make the replacement?

4

2 回答 2

3
s/\$__REQUEST\[(.*?)]/$this->input->post(\1)/

.*?匹配从[一个 ]而不是最后一个的所有内容,尽管在这种情况下它不太重要。

顺便说一句,PHP 超全局是$_REQUEST而不是$__REQUEST

于 2013-07-30T19:30:18.670 回答
2

您可以使用正则表达式在 Notepad++ 中执行此操作。代替

\$_REQUEST\['([^']*)'\]

$this->input->post('$1')

如果你也有双引号,你可以使用更复杂的表达式来处理这两种情况,尽管我不确定 Notepad++ 是否支持反向引用;代替

\$_REQUEST\[(['"])(.*?)\1\]

$this->input->post($1$2$1)

请注意,我已恢复使用此处建议的 @ExplosionPills (.*?)——实际上它可能会更好。

于 2013-07-30T19:30:53.403 回答