Re: Regex advice

[email protected] ("John W. Krahn")
Newsgroups perl.beginners
Message-ID <[email protected]>
Steve Bertrand wrote:
>>> 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'.

The \w character class matches any "word" character where "word" is 
defined as any alphabetic character or any numerical digit or the '_' 
character.  The '|' which is used for alternation outside of a character 
class just matches a literal '|' character inside a character class. 
The \s character class matches any whitespace character.


> 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?

I don't think I understand your last question.



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall
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.