help tweaking regular expression in perl
Can some开发者_JAVA技巧one help me tweak this regex? It's grabbing 72.49 GB
and I'm ONLY interested in the value 72.49
$line =~ m/(backup-size)[:=](.+)/
Raw String:
Tue Jan 04 05:45:34 2011: db2.mil.mad:backup:INFO: backup-size=72.49 GB
Try this:
$line =~ m/backup-size[:=]([\d.]+) GB/;
To select both the size and the unit in separate groups:
$line =~ m/backup-size[:=]([\d.]+) (.B)/;
$line =~ m/backup-size[:=](\d+\.?\d*)\s*[KMG]B/i;
精彩评论