|
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
|