Reputation: 1210
My regex is supposed to substitute a date in a larger csv file with the word 'TIMESTAMP'.
TEXT12, TEXT312, 22.11.2013 13:30:16, abcd,
while(<>) {
s/[0-9]{2}.[0-9]{2}.[0-9]{4}\s[0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/;
print $_;
}
I checked the regex with RegexBuddy, it matches there successfully, but in the Perl program it doesn't work. Tried with Perl 5.14 and Perl 5.18 on Linux and Windows, no success.
Where is the mistake?!
Upvotes: 0
Views: 85
Reputation: 50637
Answer is in your csv file, you might have several white spaces between numbers so use \s+
s/[0-9]{2}\.[0-9]{2}\.[0-9]{4}\s+[0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/;
Also, when you want to match literal .
char you have to escape it \.
or use regex class for it [.]
Upvotes: 1
Reputation: 2064
You have to escape dots .
.
Try this one:
s/[0-9]{2}\.[0-9]{2}\.[0-9]{4}\s[0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/;
Upvotes: 1