Page 1 of 1

Replace by Array?

Posted: Fri Apr 30, 2010 10:00 am
by PeteTheBloke
Not sure how to phrase this but PHP users will know what I mean.

I want to search for 1 2 and 3 and replace them with 5 6 and 7 respectively.

In PHP I might use str_replace(array(1,2,3) , array(5,6,7), string )

Posted: Fri Apr 30, 2010 11:44 am
by PeteTheBloke
Came up with a solution. Maybe it'll help someone.

I put all the lookup list in a table in a database:

1 fred
2 bert
3 george

etc. I had 260-odd rows.

Then I filled another table like this:
INSERT INTO tbl_name SET other_ref = (SELECT uid FROM tbl_lookup WHERE name = 'fred') , etc. etc.

I was able to use normal regex to make the 25000 lines from csv to SQL as above. And now it's all working.

Posted: Fri Apr 30, 2010 11:45 am
by ben_josephs
Search for: (1)|(2)|(3)

[X] Regular expression

Replace with: ?1x:?2y:?3z

[ ] Literal replacement [i.e., not selected]

Options
Replacement format syntax
[X] Extended
Search for conditional "extended format" in the help.