Monday, October 11, 1999, 1:51:23 AM, Ali wrote:
> Should I take it to mean then that only those who are already familiar
> with it would have use for it?

    Well, no.  Regexps are one of those features where you don't know you'd
use it until you learn it and use it.  Once you do then whenever you find
yourself in a situation that would be solved nicely and neatly with them and
they are not present it is like missing a limb.  Sure, you can get the job
done another way but it takes a while to do it.  ;)

    Regexps are somewhat complex.  In fact, O'Reilly has a book out on just
using regexps in various incarnations.

    Just a quick off the cuff example of regexps, perl style.  Say you wanted
to search lines in a text file for an ip address notation, reverse it, then
stuff it into another variable.  The short perl script would be:

while(<>){
  if ($_ =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/){
    $reversedip = "$4.$3.$2.$1";
  }
}

The regexp is this:
/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/

    That is a pattern which means "Any digit with 1-3 characters, dot, any digit
with 1-3 characters, dot, any digit with 1-3 characters, dot, any digit with
1-3 characters."  The parents around the "\d{1,3}" tells the regexp engine to
stick that into what I call a "register" which can be used later on in the
expression or later on in the language.  In this case, the first match is put
into register 1, the second into register 2 and so on.  Then on the line
inside the if I just assigned the registered in a reverse order to another
variable.

    That is a simplistic view.  Regexps can match strings at the beginning of
the line, end of the line, have different subsets that they can match against
(\w for alphanumeric, \d for digit, \s for whitespace, etc), match single
characters (\s), none-to-any(\s*), one-or-more(\s+), a specific number or range
of characters(\s{1}, \s{1,4}, etc.  Add to that the substitution and translation
that some variations allow and it gets even more powerful.

    Anyway, to get back to TB!, here is the changes entry that explains the
regexps:

[!] Perl-compatible Regular Expressions string matching when searching text in
Message Viewer (Find Text), Message Editor (Find Text / Replace Text), Message
Finder (see Advanced Tab), Sorting/Office filters (see Options Tab).

[+] %REGEXPTEXT & %REGEXPQUOTES macros.

    I'd have to play with it to see exactly how it works, but for me the most
obvious use of regexps in an email client would be to develop filters around
them and then use the registers from the filter to tell the program where to
sort the mail to.

    For example, the mailing lists I run always have the following line in the
headers...

X-list: swprivateer

    ...so if I had regexp I could construct one like this...

/^X-list: (.*)/

    ...which tells it to match any string which starts with "X-list: " and
then place the remainder of the string in the first register.  Run against the
above line the first register would contain the word "swprivateer".  Now, tell
it to move the message to ".\Mailing Lists\$1" (example, I dunno if or how TB!
uses registers) and the mail is filed to ".\Mailing Lists\swprivateer".

    But here is the important part.  That one filter will now match *ANY*
message sent from a list server that uses X-List and file it into a separate
folder.  I no longer need to add a filter for each mailing list, now it is
just for each mailing list software.  After covering Majordomo and LISTSERV,
the two most common mailing list servers out there) a majority of mailing
lists will be filtered automatically with no intervention from the user.

    Again, that is but a simplistic example of what regexps could do.  I guess
what I'm trying to say in my long-winded style is that regexps are an
excellent tool for manipulating text and email, being a text-based medium, is
an application exceptionally suited for their use.

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
         ICQ: 5107343          | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------

-- 
--------------------------------------------------------------
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team click here:
   <mailto:[EMAIL PROTECTED]>
To Unsubscribe from TBUDL, click below and send the generated message.
   <mailto:[EMAIL PROTECTED]>
--------------------------------------------------------------

Reply via email to