CartMetrix - Do you know yours?

« Bootp Session Transmit Error | Home | Outlook Express Uses 100% CPU »

6/25/2007

Grep Replace and Word Processing

I spend so much time in a text editor, its hard to get my head around a word processor sometimes. Text and formatting at the same time?

Moving some content around I found myself with a ton of links formatted in an unordered list. I only needed the plaintext of the name and link separate for the current project. My trusty BBEdit with Grep search and replace support yield the following search and replacement patterns to make quick work of the list.

Search Grep Pattern

<li><a href=“(.*)”>(.*)<\/a> ?<strong> ?\((.*)\)<\/strong><\/li>

Replace Grep Pattern

\2\t\(\3\)\r\1\r

Turned this

<li><a href=“http://www.agentb.com/”>AgentB</a> <strong> (Deals)</strong></li>

into this

AgentB (Deals)
http://www.agentb.com/

I always keep an empty BBedit window for text processing like this. Its easy to paste a chunk of text, process it and then paste it back into your word processor.

Note:
I’m almost good enough at Grep search patterns to make this viable in all situations. It used to take me 5 minutes to debug and expression that would have taken 2 minutes to cut and paste manually. I had this one whipped out in much less time than it would have taken to manually cut and paste a hundred of these.

Popularity: 22%

Trackback:

Related Posts

Post your opinion

Verification Image

Please type the letters you see in the picture.

Subscribe without commenting


damonparker.org is proudly powered by WordPress
Entries (RSS) and Comments (RSS).

copyright © 2002-2008 damonparker.org. all rights reserved.

Close
E-mail It