-2

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?

anubhava
  • 761,203
  • 64
  • 569
  • 643
user2670167
  • 77
  • 5
  • 17

2 Answers2

0

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'

Ander2
  • 5,569
  • 2
  • 23
  • 42
0

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@",
Jerry
  • 70,495
  • 13
  • 100
  • 144