Hi Alan,
On 5/19/06, Alan Campbell wrote:
hello folks,
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!)
I think using character classes and nonbacktracking groups can speed
up the .* stuff. Maybe something like the following will help?
/(?:(?>[^S\n]*)S?)*ST\S+\s*\S*B15--(?:(?>[^02468\n]*)[02468]?)*[^02468]\]/mg
David
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>