[LCP] input needed

Mike or Penny Novack stepbystepfarm at mtdata.com
Mon Jul 23 17:25:44 UTC 2007


>>A regular expression is a sentence?
>>
>>Zach
>>
>>    
>>
No Zah, not hardly.

"Regular Expression" matching is searching for and matching to some 
"pattern". The way you express what you want to be matched is by 
supplying the matcher with a string, and this string is known as a 
"regular expression".

Think of this as the big brother of the sort of "find string" you are 
used to using. You might have used relatively simple things like 
"wildcard" characters. But let's say you wanted to match.......

Find all places in the text where the word "abc" is followed by the word 
"xyz" and there are exactly three other (unspecified) words in between.
By saying word "abc" I mean just that, ignore strings like " xabc " or " 
abcx "
And we'll consider "word" (the in between words) to be anything that 
looks like it might be  a word, not necessarily meaningful in the langauge.

So the match SHOULD select  "  abc always eats ghy xyz  " (it won't 
matter that "ghy" is nonsense)
It should not match                   "  abc is a three letter string 
like xyz " (more than three intervening words

So what I am saying is that you could (once you have learned how) write 
a "regular expression" which will represent this match process. Trust 
me, will take some practice before you learn to write the correct 
"regular expression" to match exactly what you want it to and nothing else.

Try a few simple exercises:
1) Find all instances of words begining with "b" and ending in "g"
    In other words, match " big " or " bag" or " begining " but not 
"beginings " and not " abridging "
2) Find the words (whatever they are) that occur two words before the 
words that mathced exercise 1.

Michael

PS -- History - Once upon a time there was a string processing langauge 
called SNOBOL designed to do stuff like this (though in a formal sense, 
a "complete" language). The 'nix shells are essentially "string 
processing languauges" and utilities were included to retain the 
capabilities of SNOBOL. Nobody uses SNOBOL these days (AFAIK).

PSS -- I can't be of much help debugging your attempts because lost all 
my computer books in a house fire last November and until we have 
repairs on a few more rooms completed we can't be replacing many books 
(nowhere to put them).




More information about the linuxCprogramming mailing list