![](/img/trans.png)
[英]Perl regex interval to match strings that correspond to hexadecimal numbers
[英]perl regex match with numbers
我正在嘗試匹配以下內容(以下內容位於名為@abc的數組中):
goo foo tool: 1.2.1 (a3 change: 234342 @ 2014/02/19 14:20:27)
與
my $match = "goo foo tool: (\d+)\.(\d+)\.(\d+) \(a3 change: \d+ @ #DATE# #TIME#\)";
在我的代碼中
78 foreach (@abc){
79 print "$_\n";
80 if ($_ =~ m/$match/){
81 print "$1\n";
82 } else {
83 print "not matched\n";
84 }
85 }
我看不到為什么打印“不匹配\\ n”;
有人知道為什么嗎?
#DATE#和#TIME#字符串常量不會與您擁有的日期匹配。 只需將其調整為正則表達式即可實際匹配這些值:
my $match = "goo foo tool: (\d+)\.(\d+)\.(\d+) \(a3 change: \d+ \@ \d+/\d+/\d+ \d+:\d+:\d+\)";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.