Zubinix has asked for the wisdom of the Perl Monks concerning the following question:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: What does this regex do?
by davido (Cardinal) on Sep 22, 2006 at 06:56 UTC | |
It should (assuming a match) capture a series of values from $file into the array @cvs. The matching occurs like this (explanation brought to you by YAPE::Regex::Explain):
The preceeding explanation is the output from the following test code:
When deciphering a regular expression, it's often helpful to use the /x modifier so you can lay the regular expression out in smaller chunks that are easier to digest.
Dave | [reply] [d/l] [select] |
Re: What does this regex do?
by bart (Canon) on Sep 22, 2006 at 08:35 UTC | |
/((?:(?:[^\n@]+|@[^@]*@)\n?)+)/gsJust a bit of optimization: I think the inner noncapturing parens would better be replaced with a "cut" (non-backtracking) pattern. You have nested plusses, and that could occasionally go very awry. See Jeffrey Friedl's book on regular expressions for a detailed discussion. Oh, as there are no dots in the pattern, the /s modifier is useless.
There. That should match the same things, but without danger for near-endless backtracking. Never mind the warning in perlre, I see no reason why this particular feature would have to change as it has been in use for many years, and unlike other extensions like (?{ CODE }) and (??{ EXPR }), it is very simple, and effective. For the latter extensions, I think they'll stay too, although the API may still change. (They are not simple.) | [reply] [d/l] [select] |
Re: What does this regex do?
by Anonymous Monk on Sep 22, 2006 at 06:54 UTC | |
| [reply] [d/l] |
by graff (Chancellor) on Sep 22, 2006 at 13:12 UTC | |
| [reply] |
Re: What does this regex do?
by pbeckingham (Parson) on Sep 22, 2006 at 13:16 UTC | |
Approximation: it captures single lines that do not contain @, and multiple lines (if possible) containing patterns that start and end with @. Not that it helps much, but here it is in action. Anyone have ideas on what it's trying to find? and the output is:
pbeckingham - typist, perishable vertebrate. | [reply] [d/l] [select] |