in reply to Explain a regex
$RE{num}{real} is created by the real_creator subroutine in Regexp/Common/number.pm; this highly flexible subroutine builds a custom RE from parameters ($base, $places, $radix, $sep, $group, $expon). For example, the code that creates $RE{num}{real} is:
pattern name => [qw (num real -base=10), '-places=0,', qw (-radix=[.] -sep= -group=3 -expon=E)], create => \&real_creator, ;
Although I see a few places where special cases of sub-expressions could be recognized and automatically replaced with their simpler forms (e.g. {0,} becomes *, and base-16 [0123456789ABCDEF] becomes [0-9A-F]), I do not disagree with the module author's choice to leave those cases in their general form; the module code is clearer, and is less likely to produce incorrect REs, than if it included code to "tighten-up" the RE.
In short, the RE is optimized for clarity and correctness in the generating code, rather than for clarity or conciseness in the RE itself.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Explain a regex
by BrowserUk (Patriarch) on Jan 22, 2005 at 23:58 UTC |