FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Mayfly: Anyone here good with regular expressions?

   
Author Topic: Mayfly: Anyone here good with regular expressions?
Chris Bridges
Member
Member # 1138

 - posted      Profile for Chris Bridges   Email Chris Bridges         Edit/Delete Post 
We used to use a 3rd party photo print service. We no longer do so, and I need to remove the specialized URLs that still refer to it from our website. There are a few thousand of them.

Dreamweaver allows regular expressions in its search and replace function, but as far as I can tell there is no way to use a single wildcard to find a variable amount of text.

What regular expression would I use that could find all of these chunks of code?

| <a href="http://fictitioussite.com/perl/ptp/oursite?photo_name=/downloads/photoname040408.JPG&title=Photo caption">BUY THIS PRINT</a>

| <a href="http://fictitioussite.com/perl/ptp/oursite?photo_name=/special/woohoohoo/otherphotoname072309.JPG&title=Other photo caption">BUY THIS PRINT</a>

| <a href="http://fictitioussite.com/perl/ptp/oursite?photo_name=/otherotherphotoname121206.JPG&title=Other other photo caption">BUY THIS PRINT</a>

The domain name is the same, the closing code is always the same, but after that the URLs are of wildly varying lengths and characters, and as far as I can tell DW's regex only handles single characters. Any suggestions?

I can also use Homesite or another text editor if that would help. Anything beats manually editing thousands of pages.

Posts: 7790 | Registered: Aug 2000  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Are you completely sure there's no "the preceding item 0 or more times" in these regexps?

Is there an "this item optional" marker? As a crude kludge, you could do (optional: any character) and do the repetition by hand.

Failing that, I can only suggest you go to some editor with a more powerful regexp system.

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
The Dreamweaver regex tutorial shows that it has pretty much all the standard regex capabilities: http://www.adobe.com/devnet/dreamweaver/articles/regular_expressions.html

So, to do the replace about as I guess you'd want to do it, you'd do the following.

In the find box (assuming title is always present):

code:
http://fictitioussite.com/perl/ptp/oursite?photo_name=(.+)&title=(.+)

And in the replace box:

code:
http://our.new/photo/url/prefix$1?title_if_we_want_it=$2

Note: not tested, but should be about right. There could be a thing or two you'd want to escape, though the . in ".com" likely isn't one of them (too specific a location to matter).
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Chris Bridges
Member
Member # 1138

 - posted      Profile for Chris Bridges   Email Chris Bridges         Edit/Delete Post 
What I want to do is find all those URLs and remove them entirely. so that

Photo by Photographer Name | <a href="http://fictitioussite.com/perl/ptp/oursite?photo_name=/downloads/photoname040408.JPG&title=Photo caption">BUY THIS PRINT</a>

becomes

"Photo by Photographer Name"

Posts: 7790 | Registered: Aug 2000  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
If Dreamweaver has the usual regexp options as fugu says, then I'm confused about what the problem is. Can you give some detail on what you've tried so far, and what result you got that you didn't like?
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
That should be easy, then. Just add more surrounding stuff to the first regex, then put nothing in the replace field and do a full search/replace.
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Shmuel
Member
Member # 7586

 - posted      Profile for Shmuel   Email Shmuel         Edit/Delete Post 
Search for:

\| <a href="http://fictitioussite\.com/perl/ptp/oursite\?.+?PRINT</a>

Replace with nothing.

(Assuming that there are no links you want to keep to that site and path which are preceded by a vertical bar and a space.)

Posts: 884 | Registered: Mar 2005  |  IP: Logged | Report this post to a Moderator
Chris Bridges
Member
Member # 1138

 - posted      Profile for Chris Bridges   Email Chris Bridges         Edit/Delete Post 
Shmuel's worked perfectly, thanks!

That was the first one I tried when I got in this morning, so fugu13's may work just as well. I'll try that elsewhere (first one is still replacing).

Posts: 7790 | Registered: Aug 2000  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Mine wouldn't work for what you want without tweaking as I indicated, which would basically make it Shmuel's.
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2