Question

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.

Was it helpful?

Solution

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.)

OTHER TIPS

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.

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 \.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top