views:

40

answers:

1

Hello all,

I have a WordPress blog with numerous URL's I wish to replace from this:

http://www.oldwebsite.co.il/name/*.asp

To this:

http://www.newwebsite.com/?p=*

For example, from this:

http://oldwebsite.co.il/name/65971.asp

To this:

http://www.newwebsite.com/?p=65971

I believe the following plugin: http://urbangiraffe.com/plugins/search-regex/ will do the trick with regex, but I am looking for the correct regex to use here.

I found this stackoverflow thread that has a similar task, but since I am not too apt with regex, I was hoping for help so I don't mess anything up.

Thanks,

Tal

+2  A: 

Search for the regular expression:

http://oldwebsite\.co\.il/name/(\d+)\.asp

and replace with:

http://www.newwebsite.com/?p=$1

In PHP:

$after = preg_replace('%http://oldwebsite\.co\.il/name/(\d+)\.asp%', 'http://www.newwebsite.com/?p=$1', $before);
Jan Goyvaerts
You may want `http://(?:www\.)?oldwebsite`.
Kobi
you have to escape 'backslashes and forwardslashes' or wrap your pattern in |pattern-goes-here| using || you dont have to escape characters.
Pragati Sureka
My PHP code uses % signs to delimit the regex so I don't have to escape forward slashes. Using | to delimit the regex is a bad idea because | is a regex metacharacter.
Jan Goyvaerts