procmail
[Top] [All Lists]

Re: $MATCHing on the left

1999-09-04 07:48:13
era eriksson <era(_at_)iki(_dot_)fi> writes:
...
Some regular expression engines will let you say (regex)\{5\} but
Procmail doesn't have that facility. There's also (regex)\{1,5\} which
means "at least one but no more than five" and which is useful when
you can't be sure there will always be five characters there (the
above condition will fail altogether if they aren't there); in
Procmail, that would have to be phrased something like this:

   * ^Subject: Same Text Here Always.*\/\
      [fwsyxzm0-9][fwsyxzm0-9]?[fwsyxzm0-9]?[fwsyxzm0-9]?[fwsyxzm0-9]?

When emulating the (regexp)\{n,m\} syntax, the 'optional' repetitions of
(regexp) should be grouped successively with parens so as to allow the
regexp engine only one possible match for the actual text.  For example,
the above should be written:

    * ^Subject: Same Text Here Always.*\/\
        [fwsyxzm0-9]([fwsyxzm0-9]([fwsyxzm0-9]([fwsyxzm0-9][fwsyxzm0-9]?)?)?)?
 

In general, (re)\{n,\m} should be expanded as:

            n times        m-n times     m-n times
         /           \  /             \  /       \
        (re)(re)...(re)((re)((re)...(re)?)?)?)...)?


Philip Guenther

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