Re: string matching specific number of times



tester <tester@xxxxxxxxxxx> wrote in comp.lang.perl.misc:
> Hi All,
>
> My CPU taking 100% if I try to match more than the existing number of
> specific matches in a string. Script is ...
>
> my $something = "this is a test, just test, no kidding, small test, but
> error in test. over over";
> if ($something =~ m/((.*)test(.*)){5}/){
> print "number of matches are 5, successful";
> }
> else{
> print "no 5 matches, failure";
> }
>
> String "test" is repeated only 4 times in $something but if I am trying
> to check whether the $something has 5, my CPU taking 100%. What is the
> issue?

Probably excessive backtracking. Lots of alternatives have already been
proposed.

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
.



Relevant Pages

  • Re: string matching specific number of times
    ... tester wrote: ... > My CPU taking 100% if I try to match more than the existing number of ... > specific matches in a string. ... Script is ... ...
    (comp.lang.perl.misc)
  • Invalid procedure call or argument: mid
    ... I am getting the error indicated below when I run the a script ... containing the code at the bottom. ... The 6, 65, and the string are the ... Copyright Microsoft Corporation 1996-2001. ...
    (microsoft.public.scripting.vbscript)
  • string matching specific number of times
    ... My CPU taking 100% if I try to match more than the existing number of specific matches in a string. ... Script is ... ...
    (comp.lang.perl.misc)
  • Re: Script To Parse A Text File?
    ... Dim x ... > 'Bottom of text file ... > I need a script that will take the 1178 and assign it to a string value. ...
    (microsoft.public.windows.server.scripting)
  • Re: Barometer for building height
    ... floor, mark the string, pull it up, measure the length of the string. ... the Reflective method - place the B at the bottom of the building, ... energy is proportional to the number of revolutions of the shaft. ... distance from the building. ...
    (rec.puzzles)