Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: regex not working

by gwhite (Friar)
on Jan 29, 2005 at 16:37 UTC ( [id://426248]=note: print w/replies, xml ) Need Help??


in reply to Re: regex not working
in thread regex not working

If I only want up to the . and it does not always appear (different databases return different format strings for that portion of the date/time) will this:

/^(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/

get it done? I am a regex incompetent.

g_White

Replies are listed 'Best First'.
Re^3: regex not working
by ZlR (Chaplain) on Jan 29, 2005 at 18:18 UTC
    To me this last expression will not match if a . is indeed present.

    So if you don't know wether or not the milliseconds have a decimal part or not you could do :

    /^(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+(?:\.\d+)?)$/

    $6 will then hold the ms, with or without the optional decimal part.

Re^3: regex not working
by sh1tn (Priest) on Jan 29, 2005 at 17:37 UTC
    What about the rough regex:

    /^.*?(\d+)\D(\d+)\D(\d+)\D(\d+)\D(\d+)\D((\d+)\.?(\d*)+)\D?/;

    which takes care to match 6 times digits delimited in some way?

    So you'll always get the:

    ($year, $month, $mday, $hour, $minutes, $seconds) = ($1, $2, $3, $4, $5, $6);
Re^3: regex not working
by saskaqueer (Friar) on Jan 29, 2005 at 17:51 UTC

    Yes, that will do exactly as you've stated. This is where you can try it yourself in a simple test case:

    while ( chomp($_ = <DATA>) ) { print /^((\d+)\-(\d+)\-(\d+)\s+(\d+):(\d+):(\d+))/ ? "Matched on '$_': $1\n" : "Unmatched on '$_'\n"; } __END__ 1990-01-01 00:00:00.000 1990-01-01 00:00:00.000 1991-08-06 12:21:12 1991-08-07 13:41:15.65 1992-09-2110:10:10.100
Re^3: regex not working
by sh1tn (Priest) on Jan 29, 2005 at 17:41 UTC
    If you want only up to '.' then use $7 instead of $6.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found