Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am working on a log file scanner to report on hack attempts and I am using a regular expression to find occurances of signatures. In one case I want to find cases where the same character is repeated 10 times or more. For example finding a string of "NNNNNNNNNN" in the log file.

I tried the following RE among others but they all return any strings that are longer than 10 characters.
if ($_ =~ /\w{10,}/io)

Replies are listed 'Best First'.
Re: RegEx for the same character repeating N times
by gjb (Vicar) on Dec 31, 2002 at 18:10 UTC
    /(\w)\1{9,}/ should do the trick.

    Hope this helps, -gjb-

    Update: Sorry, forgot about the "or more", so added the ','.

      Thank you. That works.
Re: RegEx for the same character repeating N times
by pfaut (Priest) on Dec 31, 2002 at 18:15 UTC

    Try this:  m/(.)\1{9,}/. This should match any character followed by 9 or more occurences of itself./p>

    --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';