Re: string matching specific number of times
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 29 Sep 2005 06:40:10 -0700
tester wrote:
> 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";
Instead of forcing the regexp engine took look for all the .*
repeatedly, why not just determine how many instances of 'test' there
are, and compare that to the number you want?
my @tests = $something =~ /test/g;
if (@tests == 5){
print "Success\n";
} else {
print "Failed, found " . @tests . " copies of 'test'\n";
}
Paul Lalli
.
- Follow-Ups:
- Re: string matching specific number of times
- From: ced@xxxxxxxxxxxxxxxxxxxxx
- Re: string matching specific number of times
- References:
- string matching specific number of times
- From: tester
- string matching specific number of times
- Prev by Date: Re: ARGV interpretation in s///
- Next by Date: regex replace credit card numbers with *
- Previous by thread: string matching specific number of times
- Next by thread: Re: string matching specific number of times
- Index(es):
Relevant Pages
|
|