Re: Regex advice

[email protected] (Rob Dixon)
Newsgroups perl.beginners
Message-ID <[email protected]>
John W. Krahn wrote:
> Steve Bertrand wrote:
>> Hi everybody,
> 
> Hello,
> 
>> I am far from a regex guru, so I know that I can get advice on how to 
>> learn to improve my regex knowledge so I can better my currently working 
>> code to protect against failure in the future. I would appreciate some 
>> criticism, with explanations as to the changes if possible.
>>
>> I've made it as brief as possible, with hopefully enough context (sorry 
>> if it wraps):
>>
>>
>> while (<LOG>) {
>>
>> if (/.*simscan~\[\d+\]~([\w|\s]+).*?~(\d+\.\d+)s~.*?~(.*?)~(.*?)~(.*)/) {
> 
> The .* pattern at the beginning is useless as it causes unnecessary 
> back-tracking, just remove it.

That depends on the target data. If the rest of the regular expression matches
the target string in more than one place then preceding it with .* forces it to
match the last occurrence. Without that it matches the first occurrence.

Rob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.