开发者

perl regex help matching varying number values

Looking for some help with this perl regex.

I need to extract (3) items from this filename: abc101.name.aue-abc_p002.20110124.csv

abc101.name.aue-abc_p002.20110124.csv

where item (3) in this example 002, can also be a max of 4 digits, 0002

Here's my non working regex:

while (my $line=<>) {
  chomp $line;开发者_运维问答
    if ($line =~ m/abc(d{3}).name.(w{3})_p([0-9]).[0-9].csv/) {
      print $1;
      print $2;
      print $3;
    }
  }


while (my $line=<>) {
  chomp $line;
  if ($line =~ /^abc(\d{3})\.name\.(\w{3})-abc_p(\d{1,4})\.\d+.csv$/) {
    print $1;
    print $2;
    print $3;
  }
}


You are missing a few plus signs (or { } quantifiers) and escaping the dots: abc(d{3})\.name\.(w{3})_p([0-9]{3,4})\.[0-9]+\.csv/


Untested: /^abc(\d{3})\.name\.([a-z]{3})-abc_p(\d{1,4})\.\d+\.csv$/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜