Perl Pattern Matching

Soldato
Joined
14 Feb 2006
Posts
4,644
Location
Surrey, UK
Evening all,

Anyone any good at this?

Basically I have a UTC time in a string in ISO 8601 format, looks something like

2008-11-26T18:01:13.00Z

I need a string which is just "hhmmss". Can anyone write a
$formatted =~ XYZ
type thing for me to do this?

Would appreciate it a lot.

Jon
 
Edit: done it.

For those who care I used:
$result =~ m/GPSD,D=(\d+)-(\d+)-(\d+)\w(\d+):(\d+):(\d+)\.(\d+)\w/;

The GPSD bit is because this is interpreting a serial GPS device on a Linux machine.

Please could a Don close this? Thanks
 
as it is so specific you could use:

$result =~ /\d{4}-\d{2}-\d{2}T(\d{2}):(\d{2}):\d{2}\.\d{2}\w/;

this would stop is accidently matching anything else (although I am not sure it is applicable in your case. Also you don't have to bracket all the parts, just the ones you want to extract or the characters you wish to group in the case of [^(123)] - exclude the pattern "123".
 
Fantastic, thanks everyone. The system has a lot of testing coming its way in the next few months, and if my way doesn't work I'll try yours daven.

The device is a TS-7260 Single Board system running Debian, if you're interested. It's being used as a flight computer in a weather balloon.

Thanks again :)
 
Back
Top Bottom