我正在寻找一种模式来匹配这个:
(单词单词单词单词) | 1234.5678% | (1234)
我想将(单词单词单词单词)保留为$ 1,将(1234)保留为$ 2
输入文件如下所示:
Header Crap | More Header Crap|Header Crap | More Header Crap|(words words words words) | 1234.5678% | (1234) | (words words words words) | 1234.5678% | (1234)(words words words words) | 1234.5678% | (1234) | (words words words words) | 1234.5678% | (1234)(words words words words) | 1234.5678% | (1234) | (words words words words) | 1234.5678% | (1234) | (words words words words) | 1234.5678% | (1234) | (words words words words) | 1234.5678% | (1234)
我认为这个问题与输入有关。它以一个大块的形式出现(IE $_ 是一大串数据,需要对其进行解析才能找到匹配项)
我尝试过的事情:
while ($_ =~ /(.*)\|{1}\d*?\.{1}\d*?%{1}\|{1}(\d*)/ {
do stuff with $1 and $2
}
也
@matches = $_ =~ /(.*)\|{1}\d*?\.{1}\d*?%{1}\|{1}(\d*)/
还有一大堆其他类似的变体。我只是在寻找正确方向的指导。任何帮助将不胜感激!