开发者

perl pattern match Downloaded: 1 files, 8.7K in 0s (16.9 MB/s)

I have the following string "Downloaded: 1 files, 8.7K in 0s (16.9 MB/s)" which I got from wget and want to pattern match it by making a regular expression of it.

I tried with:

/^Downloaded: ([0-9]*) files, ([0开发者_StackOverflow中文版-9GK]*) in ([0-9.]*)s ([0-9.]) [KM]B\/s/ 

But it does not work. I would appreciate any help. Thanks!


"Downloaded: 1 files, 8.7K in 0s (16.9 MB/s)"

does not match /^Downloaded: ([0-9]) files, ([0-9GK]) in ([0-9.]*)s ([0-9.]) [KM]B\/s/ because of the decimal point in "8.7K", and the parentheses around the download speed. Change that to:

/^Downloaded: (\d+) files, ([0-9.]+[GMK]) in ([0-9.]+)s \(([0-9.]+) [KM]B\/s\)/

I also made it so some of these values can have more than one digit, and you can have files that are in the megabyte range as well as kilobyte and gigabyte.


A character class like [0-9] only matches a single character. If you want one or more you should specify [0-9]+. Also, you forgot the dot in the character class for the size.

Also you could use \d+ instead of [0-9]+.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜