Re: Regex advice

2008-06-04 Thread Rob Dixon
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 so

Re: Regex advice

2008-06-04 Thread Steve Bertrand
What I mean is, if you were to use a regex as opposed to using split(), how would you have written: if (/.*simscan~\[\d+\]~([\w|\s]+).*?~(\d+\.\d+)s~.*?~(.*?)~(.*?)~(.*)/) { ...to do the task I originally requested help with? Aside from removing .* at the beginning and removing '|' from the

Re: Regex advice

2008-06-03 Thread John W. Krahn
Steve Bertrand wrote: 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

Re: Regex advice

2008-06-03 Thread Steve Bertrand
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 characte

Re: Regex advice

2008-06-03 Thread John W. Krahn
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 appea

Re: Regex advice

2008-06-03 Thread Steve Bertrand
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 woul

Re: Regex advice

2008-06-03 Thread Steve Bertrand
Gunnar Hjalmarsson wrote: if (/.*simscan~\[\d+\]~([\w|\s]+).*?~(\d+\.\d+)s~.*?~(.*?)~(.*?)~(.*)/) { -^^ This captures the "result", but with a trailing space. You may want to let the capturing parentheses be followed by \s to prevent that. With "captures the r

Re: Regex advice

2008-06-03 Thread John W. Krahn
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

Re: Regex advice

2008-06-03 Thread Gunnar Hjalmarsson
[ Please don't remove attributions. ] Steve Bertrand wrote: Gunnar Hjalmarsson wrote: Steve Bertrand wrote: if (/.*simscan~\[\d+\]~([\w|\s]+).*?~(\d+\.\d+)s~.*?~(.*?)~(.*?)~(.*)/) { -^^ This captures the "result", but with a trailing space. You may want to let

Re: Regex advice

2008-06-03 Thread Steve Bertrand
if (/.*simscan~\[\d+\]~([\w|\s]+).*?~(\d+\.\d+)s~.*?~(.*?)~(.*?)~(.*)/) { -^^ This captures the "result", but with a trailing space. You may want to let the capturing parentheses be followed by \s to prevent that. $result = $1 if $1;

Re: Regex advice

2008-06-03 Thread Gunnar Hjalmarsson
Steve Bertrand wrote: if (/.*simscan~\[\d+\]~([\w|\s]+).*?~(\d+\.\d+)s~.*?~(.*?)~(.*?)~(.*)/) { -^^ This captures the "result", but with a trailing space. You may want to let the capturing parentheses be followed by \s to prevent that. $result

Regex advice

2008-06-03 Thread Steve Bertrand
Hi everybody, 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