tags:

views:

96

answers:

2

I have this

/([^\/\|\#\<\(\>\;\s][0-9]*[\s][KB]{2})

in order to be specific i had to use [KB]{2} I get the value needed, but can I convert the final print to MB?

Exemple: match= 2000KB = 2MB?

Thanks

+1  A: 

Sure you can; capture the unit and the number separately like this:

/[^\/\|\#\<\(\>\;\s]([0-9]*)[\s]([KB]{2})

Assuming your original regex is correct, of course. Then:

if ($2 eq "KB" && $1 > 1024) {
    $1 /= 1024;
    $2 = "MB";
}
Borealid
I started to learn regex expressions 2 days ago, that regex was the one that worked for me, thanks for the quick answer!
raFF
If this answers your question be sure to click the check box.
jeremynealbrown
if I don't use {2} would it match KBites?
raFF
@raFF: "[KB]{2}" matches "KB" or "KK" or "BK" or "BB". "KB" matches only "KB".
Borealid
thanks, I've learned something new :D
raFF
A: 

lol on the sting "2000 KK" your regex matches

$1 = 000
$2 = KK

better try this one ;)

/(\d+)\s*(KB)/
zolex