[X-Unix] Grep and backreferences with BBEdit

Pedro fp lists at pedro.Net.au
Tue Oct 12 16:27:53 PDT 2004


My solution in BBEdit would be search for ...
	<a href='([^.]+)\.jpg'>
and replace with ...
	<a href="images/\1.jpg">

That's taking the difference in quotes in your example (you have single  
quotes in the source & double quotes in the replacement) very  
literally. Use single or double quotes in both strings if you want the  
same before & after.

On 13/10/2004, at 4:12 AM, Nick Scalise wrote:

> I do not have a strictly unix question. I am very weak at grep and  
> could use some rudimentary help.
>
> In BBEdit 6.5, I am wanting to do a search and replace for all  
> occurances of <a href="name.jpg">, where 'name' is the variable. I  
> want to add a images/ to the beginning of the 'name' variable.
>
> So, I think I have the first part figured out, I find <a  
> href="[a-zA-Z0-9+]+.jpg"> using grep in BBEdit's find dialog, this  
> seems to produce the desired result. Please let me know if there is a  
> better way.
>
> Where I am lost is the backreference part. What is the pattern I would  
> add in the replace dialog that would add 'images/'  so that the  
> original <a href='name.jpg'> would end up <a href="images/name.jpg">

Cheers, Pedro :-)

Web: <http://www.pedro.net.au>                    PGP Key ID: 387CD96F
Instant messaging...  AIM: bandidoOfOz  ICQ: 27671678  Jabber: pedrofp
                       MSN: mail at pedro.net.au           Yahoo: pedro_fp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
~~~~~~~~~~~~~
"To love. To be loved. To never forget your own insignificance. To  
never get used to
the unspeakable violence and vulgar disparity of life around you. To  
seek joy in that
saddest places. To pursue beauty to its lair. To never simplify what is  
complicated
or complicate what is simple. To respect strength, never power. Above  
all, to watch.
To try and understand. To never look away. And never, never to forget."
                                                                          
Arundhati Roy



More information about the X-Unix mailing list