Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Help with a more precise regex

by BrowserUk (Patriarch)
on Apr 25, 2003 at 20:54 UTC ( [id://253252]=note: print w/replies, xml ) Need Help??


in reply to Help with a more precise regex

A somewhat different approach. If you were using 5.8 the $^N is probably a better choice than $+ though it makes little difference in this case.

#! perl -sw use strict; for ('6d', '3h', '4d 3h','6D', '3H', '4D 3H') { our ($d,$h) = (0,0); print "$d days $h hours\n" if m[^ (?: (\d+)d (?{ $d = $+ || '0' }) )? \s* (?: (\d+)h (?{ $h = $+ || '0' }) )? $]xi; } __END__ C:\test>test 6 days 0 hours 0 days 3 hours 4 days 3 hours

Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://253252]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-24 00:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found