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

How can I use s/// to search for a specific number of characters?
s/(\x28\x00\x00.*?[25])//e;
Obviously the code above doesn't work. So how can I search for \x28\x00\x00 and then add the next 25 characters onto the search string? Thanks.

Replies are listed 'Best First'.
Re: searching for a specific number of characters
by diotalevi (Canon) on May 19, 2005 at 06:34 UTC

    Use the {...} braces to quantify. I used /s to make sure the . I used would also match \n characters (it doesn't, normally). I also removed your /e because it was meaningless and dangerous.

    s/(\x28\0\0.{26})//s
      Perfect. Thanks for your help.
Re: searching for a specific number of characters
by polettix (Vicar) on May 19, 2005 at 11:05 UTC
    Just to give you the fishing rod, you can peruse perlre for all you want to know about regexes in Perl. And here's a free fish about quantifiers:
           The following standard quantifiers are recognized:
     
               *      Match 0 or more times
               +      Match 1 or more times
               ?      Match 1 or 0 times
               {n}    Match exactly n times
               {n,}   Match at least n times
               {n,m}  Match at least n but not more than m times
    
    Note that n can be 0 in the last one. Enjoy your meal :)

    Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

    Don't fool yourself.