Reputation: 99
I need a way to search any string that contains a valid whole or partial datetime and extract it from that string, based on a strptime format.
For example, if I have:
%b%d
How can I search this string:
"asdbsdjwebzadjabsdmwAug20asdfswelasdsvclasdk"
and get some datetime representation of "August 20th" from it?
Are there any modules that allow me to convert a strptime format into a regex and search for it like that?
Any information would be helpful. Thanks!
Upvotes: 0
Views: 114
Reputation: 24083
You can use Regexp::Common::time:
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use Regexp::Common qw(time);
my $str = "asdbsdjwebzadjabsdmwAug20asdfswelasdsvclasdk";
say "matches" if $str =~ $RE{time}{strftime}{-pat => '%b%d'};
Upvotes: 3