Re: Regex advice
[email protected] ("John W. Krahn")
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
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 class. The \s character class matches any whitespace character.
>
> Ok, it makes sense now that I know that the '|' is literal in the
> context that I had it.
>
>>> 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.
>
> 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
character class the other parts should work as desired.
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