procmail
[Top] [All Lists]

Re: need help with a regular expression

2001-02-23 17:40:06
From: Philip Guenther <guenther(_at_)gac(_dot_)edu>

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.

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



        # edit next line to put as many dots in as you want chars.
        ourStringLength = "...."


            # might be a general way to find N chars in a row
        :0  # from set of [!#^]; where N is defined by $ourStringLength
        *   ? ()\/[!#^]+
        * $ ? MATCH ^^\/$ourStringLength
        {
           suspectString = $MATCH

           :0
           * ? suspectString ^^\/.
           { firstChar = $MATCH }

           :0
           * $ ! ? firstChar ^^$ourStringLength^^
           { } # if here, the string was a repeat of only one char from set

           :0 E  # if here, we match four identical chars
           | do_something

        }


I'm too tired to check whether my syntax is right.  I might have goofed
somewhere - not sure, and it's not tested.

I can think of (at least) one algorithmic flaw: suppose the string found is

        !####

That would flunk our test for four in a row like the first char,
even though it is composed only of chars from the sought set
and even though there *are* four in a row of one char from that set.
Oh, well.  One could always use a recursive INCLUDERC to loop . . . .

I wouldn't have bothered, but something gets me going whenever someone
says there's "no way."  :-)

-- 
Netcom has imploded.  Please now use NOTnetcom.com for mail.
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ex-Netcommies:  Mail "forwards" for free forwarding service!
NOT affiliated with EarthLink, Inc.'s Netcom brand identity.
_______________________________________________
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>