Reputation: 83
How to use regular expression in javascript to retrieve the datatime stamp path in different OS
Here's the example.
D:\\deploy\\logs\\uat\\20140929101121\\build1.log
//usr//bin//app1//log//dev//20140929100730//build2.log
//usr//bin//app1//log//dev//20140929100728//build1.log
And I would like to retrieve the string of
20140929101121
20140929100730
20140929100728
Upvotes: 0
Views: 66
Reputation: 415
you can also try this i used in perl.
use strict;
use warnings;
my $string = qq(D:\\deploy\\logs\\uat\\20140929101121\\build1.log
//usr//bin//app1//log//dev//20140929100730//build2.log
//usr//bin//app1//log//dev//20140929100728//build1.log);
$string =~ s{^(?:.*?)(?:[\\/]*)([0-9]{14})(?:[\\/]*)(?:.*?)$}{$1}igm;
print $string;
The Output:
20140929101121
20140929100730
20140929100728
Upvotes: 0
Reputation: 67968
(\d+)(?=[\\\/]{2}[^\\\/]*$)
You can try this.This will remove the dependency of having 14
digits.See demo.
http://regex101.com/r/lS5nP7/1
Upvotes: 0
Reputation: 4228
In the example data you provided it would be fair to say that you want 14 digits that will be followed by a path separator of either //
or \\
.
If that is the case then it is as simple as:
(\d{14})(?=[\\/]{2})
This will capture the 14 digit timestamp, where it is followed by either // or \
Upvotes: 0