Required help in perl regular expression substitution for this date format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Required help in perl regular expression substitution for this date format
# 1  
Old 06-27-2011
Error Required help in perl regular expression substitution for this date format

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.

Code:
$_ = "Date: November 25, 2010  09:02:01 PM";
if(s/\(January|February|March|April|May|June|July|August|September|October|November|December\) *[0-3]*[0-9], *[0-9]*[0-9][0-9] *[0-2]?[0-9]:[0-5][0-9]:[0-5][0-9]\(\.[0-9][0-9]\)? *[AP]M/DATE***/g) {
$flag = 1;
print "Done";
print $_;
}

It is giving the following output:
DoneDate: DATE*** 25, 2010 09:02:01 PM

I want whole of this date to be substituted with DATE***
# 2  
Old 06-27-2011
Hi,

I don't like your regular expression, but try next one (similar to yours but with little changes):
Code:
$_ = "Date: November 25, 2010  09:02:01 PM";
if(s/(January|February|March|April|May|June|July|August|September|October|November|December) *[0-3][0-9], *[0-9]{2}[0-9][0-9] *[0-2][0-9]:[0-5][0-9]:[0-5][0-9](\.[0-9][0-9])? *[AP]M/DATE***/g) {
    my $flag = 1;
    print "Done\n";
    print $_, "\n";
}

Regards,
Birei
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help required in writing the regular expression.

1 1982 1 testing init.cc 3001 Apr 25 2014 09:56:13.617 Task(0x5bac5060) tRestart (stack st:0x5bace000, end:0x5bac8000) deleted 1 1982 1 testing init.cc 3001 Apr 25 2014 09:56:13.628 Task(0x5bac5060) tRestart (stack st:... (12 Replies)
Discussion started by: VSSajjan
12 Replies

2. Solaris

Regular Expression in Date ls command

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

3. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

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)
Discussion started by: jessy83
1 Replies

4. Shell Programming and Scripting

Perl regular expression help!

Hi I am doing something basic like... if ($stringvariable =~ /have not typed/) I have a little problem because the 'not' in the expression gets highlighted as a kind of a '!'..what am I supposed to do in this situation? Thank you ---------- Post updated at 03:24 PM ----------... (1 Reply)
Discussion started by: vas28r13
1 Replies

5. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

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)
Discussion started by: kittyluva2
4 Replies

6. Shell Programming and Scripting

validate date pattern using Regular Expression

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)
Discussion started by: vvenu88
2 Replies

7. Shell Programming and Scripting

perl regular expression format date

Hi Everyone, Mon 18 Jan 2010 09:52:10 AM MYT the output is 20100118 09:52:10 how to do it in perl regular expression =~ Thanks (3 Replies)
Discussion started by: jimmy_y
3 Replies

8. Shell Programming and Scripting

Regular expression (regex) required

I want to block all special characters except alphanumerics.. and "."(dot ) character currently am using // I want to even block only single dot or multiple dots.. ex: . or .............. should be blocked. please provide me the reg ex. ---------- Post updated at 05:11 AM... (10 Replies)
Discussion started by: shams11
10 Replies

9. Shell Programming and Scripting

regular expression format string in one line.

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)
Discussion started by: jimmy_y
2 Replies

10. Shell Programming and Scripting

regular expression format

. . . AA = 0.000000, 0.000000, 0.006000, 0.006000, 1, 1.000000, 0.000000 ;item 1 #line 1 BB = -0.002990, -0.002990, 0.002990, 0.002990, 0, 1.000000, 0.000000 ;List 1 #line 2 CC = 0.023620, 0.023620, 0.035430, 0.035430, 1, 1.000000, 0.000000 ;Counter strike ... (1 Reply)
Discussion started by: trynew
1 Replies
Login or Register to Ask a Question