procmail
[Top] [All Lists]

Re: Simple (for you) regexp question

1998-11-16 10:35:09
On Mon, 16 Nov 1998, era eriksson wrote:

 > Ok, I need to match a line that can basically start with anything
 > from one word to 6, but always ends the same way. Thus far I've been
 > using .* even though that for some reason is not the way to do it (yes,
 > when it comes to procmail recipes I'm of the steal, cut and paste school)

You mean like this?

    WORD="[a-z']+\\>+"
    :0:
    * $ ^$WORD($WORD($WORD($WORD($WORD($WORD)?)?)?)?)?\>+same thing as always
    action

This is untested. (For text in a Nordic language, you should probably
add some characters with nice diacritics to the WORD definition, and
perhaps even take out the apostrophe.)

Thanks; perhaps even too specific since I just used the 1-6 to illustrate
that it could be any text at all basically, but that the line always 
ended the same way. I just wondered how are you going to match a line
that can start with anything but end with something specific without
resorting to .*

What do you mean by "for some reason that is not the way to do it"?
Yes, generally speaking, .* is too prone to accidentally match
something you didn't intend it to, so if you want to match on
something more specific, you should spell it out. Is this what you are
referring to?

Yeah. I've seen numerous times here that using .* at the beginning of
an expression is a no-no, so that's why I started wondering how else
I was supposed to do it. It works as is, I just started thinking that
perhaps it might be useful to know how to make it work more elegantly.

Regards,
        Kimmo.
--

---------------------------------+-------------------------------------+
          Kimmo Jaskari          | ÅLCOM - Ålands Datakommunikation Ab |
  E-mail: kimmo(_at_)alcom(_dot_)aland(_dot_)fi   |     
http://www.alcom.aland.fi       |
 http://www.alcom.aland.fi/kimmo |      Phone: +358-(0)18-12122        |
---------------------------------+-------------------------------------+

<Prev in Thread] Current Thread [Next in Thread>