You can't do that with just an Regex, because of the required transformation of a three-letter month to a number. However, with an suitable lookup hash, it becomes almost trivial:
Or, you can use a module like Date::Parse for it.
Hello all,
I need to match the red expressions in the following lines :
MACRO_P+P-_scrambledServices_REM_PRC30.xml
MACRO_P+P-_scrambledServices_REM_RS636.xml
MACRO_P+P-_scrambledServices_REM_RS535.xml
and so on...
Can anyone give me a PERL regular expression to match those characters ?
... (5 Replies)
Hi All,
@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
$day=091023;
$day_combine = $day;
$day_combine =~ s/({2})({2})({2})/20$1-$months-$3/;
Instead of three lines, is possible to combine the last two lines into a single line? means no need assign $day to $day_combine... (2 Replies)
Hi,
i am java guy and new to unix.
I want to validate date pattern using Regex expression
here is the sample program i have written.
#!/bin/sh
checkDate="2010-04-09"
regex="\\d{4}-\\d{2}-\\d{2}\$"
echo $regex
if ]
then
echo "OK"
else
echo "not OK"
fi
But the ouput is... (2 Replies)
Hi,
I am looking for a Perl regular expression to match the below pattern of a java script file.
var so = object.device.load('camera','value');
I want to grep out such lines present in the *.js files. The conditions are:
a) the line may start with blank space(s)
b) always the... (3 Replies)
Hello,
I am trying to use perl LWP module to read and get a specfic URL page. The issue is that the URL ends with the data and time and time is not consistent it changes all the time. if anyone could help me how to write a regular expressin that would work in the LWP::UserAgent get function to... (0 Replies)
Hi,
I have written a small perl script to handle particular date format using perl, but it is not substituting the whole string. Can some one please check on what is the issue with the code.
$_ = "Date: November 25, 2010 09:02:01 PM";... (1 Reply)
I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense.
... (4 Replies)
Hi all,
How am I read a file, find the match regular expression and overwrite to the same files.
open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat";
open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat";
while (<DESTINATION_FILE>)
{
# print... (1 Reply)
Hi,
I have got a problem in a regular expression with a file name containing date. I am using a regular to display the file in ls, but by using the same it gives me file name does not exist.
--## File exist when I do ls.
ls
amey_in20131018.csv
--## File name not showing when I use... (5 Replies)
Discussion started by: ameyrk
5 Replies
LEARN ABOUT SUSE
date::parse
Date::Parse(3) User Contributed Perl Documentation Date::Parse(3)NAME
Date::Parse - Parse date strings into time values
SYNOPSIS
use Date::Parse;
$time = str2time($date);
($ss,$mm,$hh,$day,$month,$year,$zone) = strptime($date);
DESCRIPTION
"Date::Parse" provides two routines for parsing date strings into time values.
str2time(DATE [, ZONE])
"str2time" parses "DATE" and returns a unix time value, or undef upon failure. "ZONE", if given, specifies the timezone to assume when
parsing if the date string does not specify a timezone.
strptime(DATE [, ZONE])
"strptime" takes the same arguments as str2time but returns an array of values "($ss,$mm,$hh,$day,$month,$year,$zone)". Elements are
only defined if they could be extracted from the date string. The $zone element is the timezone offset in seconds from GMT. An empty
array is returned upon failure.
MULTI-LANGUAGE SUPPORT
Date::Parse is capable of parsing dates in several languages, these include English, French, German and Italian.
$lang = Date::Language->new('German');
$lang->str2time("25 Jun 1996 21:09:55 +0100");
EXAMPLE DATES
Below is a sample list of dates that are known to be parsable with Date::Parse
1995:01:24T09:08:17.1823213 ISO-8601
1995-01-24T09:08:17.1823213
Wed, 16 Jun 94 07:29:35 CST Comma and day name are optional
Thu, 13 Oct 94 10:13:13 -0700
Wed, 9 Nov 1994 09:50:32 -0500 (EST) Text in ()'s will be ignored.
21 dec 17:05 Will be parsed in the current time zone
21-dec 17:05
21/dec 17:05
21/dec/93 17:05
1999 10:02:18 "GMT"
16 Nov 94 22:28:20 PST
LIMITATION
Date::Parse uses Time::Local internally, so is limited to only parsing dates which result in valid values for Time::Local::timelocal. This
generally means dates between 1901-12-17 00:00:00 GMT and 2038-01-16 23:59:59 GMT
BUGS
When both the month and the date are specified in the date as numbers they are always parsed assuming that the month number comes before
the date. This is the usual format used in American dates.
The reason why it is like this and not dynamic is that it must be deterministic. Several people have suggested using the current locale,
but this will not work as the date being parsed may not be in the format of the current locale.
My plans to address this, which will be in a future release, is to allow the programmer to state what order they want these values parsed
in.
AUTHOR
Graham Barr <gbarr@pobox.com>
COPYRIGHT
Copyright (c) 1995-2009 Graham Barr. This program is free software; you can redistribute it and/or modify it under the same terms as Perl
itself.
perl v5.12.1 2010-07-01 Date::Parse(3)