Msg#: 3715605 posted 5:51 pm on Aug 5, 2008 (gmt 0)
Except you need to escape the slashes or it gives you an unmatched [ error:
$date =~ s/(\d+)[\/.](\d+)[\/.](\d+)/$1-$2-$3/g;
A dissection of perl diver's code, I've added an x modifier to allow the comments and white space.
#!/usr/bin/perl $date = '08/05/2008'; print "before $date\n"; #$date =~ s/(\d+)[\/.](\d+)[\/.](\d+)/$1-$2-$3/g; $date =~ s/ # substitute this match . . . (\d+) # one or more (+) of any digit. Store this value in $1 [\/.] # followed by ONE slash or dot (\d+) # followed by one or more digits, store in $2 [\/.] # followed by another slash or dot (\d+) # followed by one or more digits, store in $3 /$1-$2-$3/gx; # replace with this. Note you can also do $3-$1-$2 # Apply globally (g), allow white space and comments(x) print "after $date\n";