I’m trying to convert strings that match /(\d)+(\.\d+)?(m|g|t)?b?/i into bytes.
For example, 1KB would return 1024. 1.2mb would return 1258291.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you reorganize the capturing group in your regex like so:
/(\d+(?:\.\d+)?)\s?(k|m|g|t)?b?/iyou can do something like: