Re: Regex advice

[email protected] (Steve Bertrand)
Newsgroups perl.beginners
Message-ID <[email protected]>
>> if (/.*simscan~\[\d+\]~([\w|\s]+).*?~(\d+\.\d+)s~.*?~(.*?)~(.*?)~(.*)/) {
> 
> The .* pattern at the beginning is useless as it causes unnecessary 
> back-tracking, just remove it.  

Ok.

> The character class [\w|\s] includes 
> both the '|' and '_' characters but it doesn't appear that that field 
> would normally contain either a '|' or a '_' character.

It wouldn't (normally). I was with a misconception on how this worked. I 
thought it meant 'capture this hunk if it contains word or whitespace in 
any amount'. I have reading to do.

>>                 $scantime = $2 if $2;
> 
> (\d+\.\d+) will always match at least three characters so it can never 
> be false so the test is superfluous.

...hrm... more reading to do.

> John

This is more about receiving feedback and not about an answer, so as I 
go find out why things work as they have been described, would you 
project the statement as if you had written it yourself, just for 
comparison sake?

Thanks everyone, as always,

Steve
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.