Adding the .png-suffix to image-Links

249 views
Skip to first unread message

frank_lapidus

unread,
Feb 22, 2011, 5:16:38 PM2/22/11
to bbe...@googlegroups.com
Hi folks,

I have the problem that in my web project there a many HTML-files (800!) with image-links without the .png-suffix;-(

Here is one example: <img align="absmiddle" alt="" border="0" hspace="5" src="../formulaPNG/70559256_1135261b2da_-7dc6" title="" vspace="5"/>

Thus I need to add the png-suffix at the end of every link and I need a wildcard for "70559256_1135261b2da_-7dc6"!

Any idea how I can achieve that?

Kind reagrds

Chaz Larson

unread,
Feb 22, 2011, 5:47:57 PM2/22/11
to bbe...@googlegroups.com
Assuming all occurences look like the sample below, you could do something like:

search for:
src="../formulaPNG/(.*)" title=

replace with:
src="../formulaPNG/\1\.png" title=

chazl

Chaz Larson - ch...@jeck.com

> --
> You received this message because you are subscribed to the
> "BBEdit Talk" discussion group on Google Groups.
> To post to this group, send email to bbe...@googlegroups.com
> To unsubscribe from this group, send email to
> bbedit+un...@googlegroups.com
> For more options, visit this group at
> <http://groups.google.com/group/bbedit?hl=en>
> If you have a feature request or would like to report a problem,
> please email "sup...@barebones.com" rather than posting to the group.
> Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
>

Ronald J Kimball

unread,
Feb 22, 2011, 6:11:20 PM2/22/11
to bbe...@googlegroups.com
On Tue, Feb 22, 2011 at 02:16:38PM -0800, frank_lapidus wrote:
> I have the problem that in my web project there a many HTML-files (800!)
> with image-links without the .png-suffix;-(
>
> Here is one example: <img align="absmiddle" alt="" border="0" hspace="5" *
> src="../formulaPNG/70559256_1135261b2da_-7dc6"* title="" vspace="5"/>

>
> Thus I need to add the png-suffix at the end of every link and I need a
> wildcard for "70559256_1135261b2da_-7dc6"!
>
> Any idea how I can achieve that?

Here's another way to do it.

I'm assuming that you want to add .png to any filename that doesn't already
have a suffix.

I'm also assuming that all the img tags use double-quotes around the value
for the src attribute, because it makes the regex simpler...


Find:

(<img\s[^>]*src="(?:[^"]+/)?[^"/.]+)"

Replace:

\1.png"


HTH,
Ronald

Alex Satrapa

unread,
Feb 22, 2011, 6:26:23 PM2/22/11
to bbe...@googlegroups.com
On 23/02/2011, at 10:11 , Ronald J Kimball wrote:

> I'm also assuming that all the img tags use double-quotes around the value

> for the src attribute, because it makes the regex simpler…

> (<img\s[^>]*src="(?:[^"]+/)?[^"/.]+)"

Because regexes are being mentioned, I am compelled to remind people about the excellent publication "Mastering Regular Expressions" - an O'Reilly book (so you *know* it's good): http://oreilly.com/catalog/9780596528126/

There is also the website http://www.regular-expressions.info/ - which is basically a big advertisement for "RegexBuddy" (but it's a Windows application, so of little use to BBEdit users)

Apologies for the diversion
Alex

frank_lapidus

unread,
Feb 23, 2011, 1:00:42 PM2/23/11
to bbe...@googlegroups.com
Heyho,

thank you very much! Maybe I'm to dumb but sadly BBEdit doesn't add the suffix .png to the links after I used your replace-string;-( It replaces something else but not the concerned links.

I attached one of my files. Would be very nice if you could check it for me once again?

Kind regards

AdiabisentZusta.html

frank_lapidus

unread,
Feb 24, 2011, 2:47:01 AM2/24/11
to bbe...@googlegroups.com
Hi Ronald,

great:-) This one worked fine for me! Thank you and the other guys for your quick help! I really appreciate it!!!

Kind regards

LuKreme

unread,
Mar 1, 2011, 1:39:56 PM3/1/11
to bbe...@googlegroups.com
On 22-Feb-2011, at 16:26, Alex Satrapa wrote:
>
> Because regexes are being mentioned, I am compelled to remind people about the excellent publication "Mastering Regular Expressions" - an O'Reilly book (so you *know* it's good):http://oreilly.com/catalog/9780596528126/

I have the second edition (about ten-twelve years old now, I guess). I don't think regex has changed that much in ten years though. Should I get the new edition?

--
National Socialism is not Socialism, any more than the Black Panthers
were actually cats. @jearl

Semper Fidelis

unread,
Mar 1, 2011, 7:37:25 PM3/1/11
to bbe...@googlegroups.com
In addition to the other fine books on regular expressions (grep's "toolbox," if you will) mentioned by other responders to this BBEdit group, I can recommend <i>Regular Expressions in 10 Minutes</i> by Ben Forta (©2004 by Sams Publishing; ISBN 0-672-32566-7). I have the Friedl book and, of course, the BBEdit manual, but it's the slim Forta book that travels with me because it's comprehensive yet svelte (102 pages if you subtract the appendices and index; 146 pages in all).

Though largely tutorial in nature, the Forta book also serves as a reference book. It's the first book I reach for if I need to noodle out a regular expression problem. The $15 book (well, $15 when I bought it in 2008) also has some "canned" regular expressions that can be used to work with such things as ZIP codes (US, UK, Canada), US Social Security numbers, credit card numbers, IP addresses, URLs, email addresses, and HTML- and Java-style comments. It even has a web link to a regular expression tester. All in all, it's a very useful addition to my collection of regex books.

Reply all
Reply to author
Forward
0 new messages