in reply to Re: Regular Exp parsing
in thread Regular Exp parsing
/^\A(\S+) (\S+) (\S+) (\d+):$/;
Also, if you truly wanted $1 to be set you could do so by just executing the regex statement provided by MarkM.
So instead of:
it would just bemy($wday, $mon, $mday, $time, $year) = $var =~ /\A(\S+) (\S+) (\S+) (\d+):/;
and $1 would be set equal to the first match$var =~ /\A(\S+) (\S+) (\S+) (\d+):/;
$2 to second
and so on
These are static/constant variables so to modify them you would have to assign them to a seperate variable as MarkM has done. If however you just need to display or store the results why generate additional variables?
If you are doing this over a large number of entries you also might want to look into optimizing your statements using the lookaheads (I think that is the correct term) which allow the regex expression to set a qualifier before attempting to match any further into the string/line/block, etc..
example
at the beginning of your regex string should help to quickly skip those lines which do not start with a capital letter from the days of the week, nifty huh?(?:[SMTWF]) warning I know my syntax is off so please don't use this.
Just my .02 cents since I love regex.
Dave -- Saving the world one node at a time
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Regular Exp parsing
by MarkM (Curate) on Dec 13, 2002 at 21:25 UTC | |
by Zapawork (Scribe) on Dec 13, 2002 at 21:44 UTC | |
by MarkM (Curate) on Dec 13, 2002 at 21:49 UTC |