Janek Schleicher wrote: > > John W. Krahn wrote at Tue, 20 Aug 2002 22:43:55 +0200: > > > > You can use \d instead of [0-9], \D instead of [^0-9] and \S instead of > > [^\s]. > > > > /^(\D+)(\d+ |)(\d+\/\S+)(.*)$/ > ^^^^^^^ > > That's still an ugly and slow way to have an optional match > better write it as > > m!^(\D+)(\d+ )?(\d+/\S+)(.*)$!
A quick test: use Benchmark; my $yes = 'x' x 100 . 333; my $no = 'x' x 100 . 'www'; timethese( -15, { bar => sub { $yes =~ /^(\D+)(\d+|)/ and $no =~ /^(\D+)(\d+|)/ }, qm => sub { $yes =~ /^(\D+)(\d+)?/ and $no =~ /^(\D+)(\d+)?/ } } ); Gives the results: Benchmark: running bar, qm, each for at least 15 CPU seconds... bar: 15 wallclock secs (15.02 usr + 0.00 sys = 15.02 CPU) @ 23001.33/s (n=345480) qm: 15 wallclock secs (15.38 usr + 0.00 sys = 15.38 CPU) @ 21303.45/s (n=327647) So it isn't really slower. YMMV John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]