Regular Expressions Saved My Life
Written by CB    Monday, 26 November 2007 17:00    PDF Print E-mail

If you've ever had to edit text files or files them selves using complex search and replace functions you sooner or later run into the problem when "search and replace are not good enough.

Well thank someone for creating "Regular Expressions" and programs like "grep".  Here's the situation, I was putting a manual written in MS Word on line and wanted to Use the table of contents (massive) as a hyper text document.

 

For Example 1 I had 2 pages of something like this to cut out and paste into a HTML document:

 

A. FORWARD...................1

1. welcome....................20

2. ect.............................35

B. INTRODUCTION.........43

 

The line endings which indicate page numbers had to be dropped , cut or replaced. Find and replace would not work, well at least not in one action. That's where regular expressions and "grep" came into play. Using something like TextWrangler (BBBedit) which has regular expressions and "grep" search and process functions I was able to whip up a search string such as:

 

(^[0-9][0-9])

 

Which says "find the last 2 numbers in each line", once I found them I replaced them with "". and presto  document cleaned up and ready for the web page. MS WORD actual put the "....." in document formatting and not in the table of contents text. If if had, regular expressions could have dealt with that as well.

 

So here's a regular expression cheat sheet.  http://www.ilovejackdaniels.com/regular_expressions_cheat_sheet.pdf

and here's a video tutorial to get you started (note it's a windows program acting like Unix).  http://www.e-texteditor.com/blog/2007/regular_expressions_tutorial



Add this article to your favorite Social Bookmarking websites
Reddit! Del.icio.us! JoomlaVote! Google! Live! Facebook! StumbleUpon! Yahoo! Free social bookmarking plugins and extensions for Joomla! websites!
Comments (0)add comment

Write comment
smaller | bigger

busy
Last Updated ( Saturday, 06 November 2010 23:07 )
 

Your are currently browsing this site with Internet Explorer 6 (IE6).

Your current web browser must be updated to version 7 of Internet Explorer (IE7) to take advantage of all of template's capabilities.

Why should I upgrade to Internet Explorer 7? Microsoft has redesigned Internet Explorer from the ground up, with better security, new capabilities, and a whole new interface. Many changes resulted from the feedback of millions of users who tested prerelease versions of the new browser. The most compelling reason to upgrade is the improved security. The Internet of today is not the Internet of five years ago. There are dangers that simply didn't exist back in 2001, when Internet Explorer 6 was released to the world. Internet Explorer 7 makes surfing the web fundamentally safer by offering greater protection against viruses, spyware, and other online risks.

Get free downloads for Internet Explorer 7, including recommended updates as they become available. To download Internet Explorer 7 in the language of your choice, please visit the Internet Explorer 7 worldwide page.