Frage

I need to replace hundreds of if (ereg("avion","$keyw")) by if (preg_match("@avion@","$keyw")) {

I tried this:

1st : ereg\("(.*)"

2nd : preg_match\("@$1@"

But it replaces the first group by '$1'... Any idea please?

War es hilfreich?

Lösung

This is working on the UltraEdit version I have:

enter image description here

I'm just not sure why you have @ in your replace.

You can pick "Current file" for all instead of the "Selected Text" I used for the comparison.

Another thing to note, it might be safer to use:

ereg\("(.*?)",

Replace:

preg_match("@$1@",

Andere Tipps

Using sed you can try this way:

sed -i".bak" 's/(ereg("\([a-z]*\)","\$keyw"))/\(preg_match\("@\1@","$keyw"\)\)/' filename

EDIT: Updated to match any word, not only 'avion'

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top