简体   繁体   中英

perl regex match with numbers

I am trying to match the following (the below is in an array called @abc):

goo foo tool: 1.2.1 (a3 change: 234342 @ 2014/02/19 14:20:27)

with

my $match = "goo foo tool: (\d+)\.(\d+)\.(\d+) \(a3 change: \d+ @ #DATE# #TIME#\)";

and in my code,

 78     foreach (@abc){
 79         print "$_\n";
 80         if ($_ =~ m/$match/){
 81             print "$1\n";
 82         } else {
 83             print "not matched\n";
 84         }
 85     }

I am not seeing why it is printing "not matched\\n";
anyone else sees why?

The #DATE# and #TIME# string constants aren't goingt to match the dates you have. Simply adjust to regex to actually match those values:

my $match = "goo foo tool: (\d+)\.(\d+)\.(\d+) \(a3 change: \d+ \@ \d+/\d+/\d+ \d+:\d+:\d+\)";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM