Alan Campbell wrote: > hello folks, Hello,
> I'm slurping in a large file and seeing a nice speedup versus line by line > processing...but I'm losing it in my (likely poorly constructed!) > reg-expression match > > I do: - > # > # look for potentially problematic code of the following form: - > # STW b0, *SP--[3] > # The reg exp tries to match: - > # - anything up until 'ST' (so that we match STH, STW, STDW etc) followed by > # - 1+ non-whitespace chars followed by > # - 0+ whitespace chars followed by > # - 0+ non-whitespace chars followed by > # the string 'B15--' followed by > # anything up until an odd single-digit number followed by > # the ']' character > # Matches all occurrences > # > my @match_sp = $all_lines =~ /.*ST\S+\s*\S*B15--.*[^02468]]/mg; > > ...and then I foreach on @match_sp to show all occurrences found... > > Any speedup tips most welcome. Would also appreciate a brief explanation of > why this reg ex is slow (so I dont screw it up next time!) Your pattern starts with '.*' and the '*' modifier is greedy so it has to match as many non-newline characters as possible and then it back-tracks to match 'ST'. You should use the non-greedy quantifier '*?' so it won't back-track. Your character class [^02468] does indeed match odd numbers, as well as every other character not '0', '2', '4', '6' or '8'. You should probably use the character class [13579] to match _only_ odd numbers. The /m option is not required because you are not using either '^' or '$' to anchor the pattern. my @match_sp = $all_lines =~ /.*?ST\S+\s*\S*B15--.*?\[[13579]]/g; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>