procmail
[Top] [All Lists]

Re: need help with a regular expression

2001-02-22 14:43:13
Michael J Wise <mjwise(_at_)kapu(_dot_)net> writes:
Douglas Otto x6849 wrote:

I am having trouble coming up with an expression that will match any
repeated special character.  For example, at least 4 or more contiguous
occurances of a character as in !!!! or #### or ^^^^, you get the idea,
without having to match them individually.  Any ideas?

      {n,} is your friend.

For more details, consult "man egrep".

How about "man procmailrc" instead?  You'll find that braces are not
listed there, because they're not special to procmail.  (They're not
special to egrep either, although GNU egrep supports \{ and \} instead.)
Furthermore, braces repeat the subregex, not the actual character matched.
With GNU egrep, the expression
        [!#^]\{4\}
matches not only !!!! and ####, but also !##!, !^#^, etc.  To do what
he wants takes 'back references', using \1, etc.  Those are availible
in grep, but not in standard egrep, nor in procmail.  They're also
incredibly slow.  To do what Douglas wants using them you would write:
        \([!#^]\)\1\1\1

but THAT DOES NOT WORK IN PROCMAIL.


The real answer is that there is no general way to match exactly N
occurences of a character except by writing out N of them.

        !!!!|####|\^\^\^\^


Philip Guenther
Procmail Maintainer
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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