Shaw
Shaw

Reputation: 1139

Perl regex to extract seconds/milliseconds from a timestamp

I am wondering if anyone could give me help with writing a regular expression to extract just the seconds and milliseconds of a particular timestamp.

example timestamp below:

15:45:30.192

I am writing this script in perl. Any help would be greatly appreciated.

Upvotes: 2

Views: 1288

Answers (2)

Jens
Jens

Reputation: 69440

This should work:

$timestamp =~ /:(\d+)\.(d+)/
$sec = $1;
$mil = $2;

Upvotes: 1

terminal ninja
terminal ninja

Reputation: 396

  1. To get them separated do the following

($sec,$millisec)=$_=~/\d+:\d+:(\d+).(\d+)/

  1. To get both second and millisecond in one variable

($time)=$_=~/\d+:\d+:(\d+.\d+)/

Upvotes: 3

Related Questions