tags:

views:

82

answers:

3
+1  Q: 

replace urls

hi there, I have a huge txt file and Editpad Pro list of urls with images on the root folder.

http://www.othersite.com/image01.jpg
http://www.mysite.com/image01.jpg
http://www.mysite.com/category/image01.jpg

How can I change only that ones that has images on the root using regexp?

http://www.othersite.com/image01.jpg
http://www.NEW_WEBSITE.com/image01.jpg
http://www.mysite.com/category/image01.jpg

I'm using the RegExr online app.

+3  A: 

Search and replace (case insensitive, regular expression):

http://www\.mysite\.com/([^/]*\.(?:jpg|gif|png))

with:

http://www\.NEW_WEBSITE\.com/\1


EDIT

And yes, this will also re-base files such as http://www.mysite.com/.jpg, if any such files or directories exist. If anyone doesn't like this then just replace * with + -- or with {X,} if your assumption happens to be that an image file needs at least a X character name s etc. etc. -- but really, this is probably quite outside the scope of what lab72 is trying to achieve (i.e. not image file name validation.)

Cheers, V.

vladr
Just a minor problem - an image file needs at least a 1 character name, right? Shouldn't that * be a +? Or do you usually use files like ".jpg"?
Chris Lutz
> an image file needs at least a 1 character name, right?No.
phihag
It works fine on EditPad Pro Portable! Thanks!!!!
@phihag - It doesn't need it, but as I said, do you ever have files called ".jpg"?
Chris Lutz
@Chris - validating filenames would be a different question. The assumption is that if the file is in the input list (be it a lonely '.jpg') then it meets the requirements and has to be rebased; I will not make assumptions about what his file names should or should not look like.
vladr
A: 

Replace

http://www\.mysite\.com/image(.*)

with

http://www.newsite.com/image$1

That being said, you might also be interested in a decent text editor. That flash applet is really yucky. You can still use the same regexp, although you'll have to replace the dollar sign $ with a backslash \.

phihag
I'm using EditPat Pro, good one, has regexpr and tabs.
I guess I should sue the author of that yucky applet for violating my trademark. Meanwhile, you can find the real EditPad Pro at http://www.editpadpro.com/
Jan Goyvaerts
+1  A: 
url1.replace(/((https?:\/\/www.?)(\w*?)(.com\/image\d*?\.(png|gif|jpg))/, 
             "$1newName$3");

Something like the above should work. The code is in AS (not compiled though :P) Note that $2 matches the sites name which we are replacing with yoursite.

dirkgently