Sureshkumar M (HCL Financial Services) wrote:
Hi All,
Hello,
I want to find the string which are having the date inside the
file.
Please help me how do I match it,below is my program and it's not
returning anything.
#!/usr/bin/perl
use warnings;
use strict;
open(DATA,"i")||die "Unable to open the file";
You should include the $! variable in the error message so you know
*why* it failed to open.
while(<DATA>)
{
if($_=~/(\d{2})([\W])\1\2\1]/)
That regular expression says: match two digits anywhere in the string
and store the results in $1, followed by a non-word character and store
the results in $2, followed by the contents of the first capturing
parentheses, followed by the contents of the second capturing
parentheses, followed by the contents of the first capturing
parentheses, followed by a ']' character.
So that will match, for example '15-15-15]'
{
print $_;
}
}
close(DATA);
exit 0;
~
Input file:
$cat i
15-06-79
05-06-1981
12-11-9
13-10-89
19-10-20009
1-10-0002
02-03-2008
03-nov-2008
$
Output should be:-
15-06-79
05-06-1981
13-10-89
02-03-2008
03-nov-2008
It looks like you want something like:
/^\d\d\D(?:\d\d|[a-zA-Z]{3})\D(?:\d\d|\d{4})$/
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/