AnswerBun.com

Is there is any way to get a size information (MB,GB) from a magnet link or a complex string in Flutter / Dart using RegEx?

Stack Overflow Asked by Harish on January 1, 2022

I am working on a personal project , where I want to get the file size information from a magnet link.

Problem:
I wanna get 7.6GB from this string below.

0-%20Giri%20(2004)%5bTamil%201080p%20HD%20AVC%20-%20x264%20-%207.6GB%5d.mkv&tr=http%3a%2f%2fbt4

I am actually new to Regex btw.

Any kind help is appreciated.(i have googled for solution , no luck)

Edit:
Thanks to Vishal Singh & Stackoverflow.

Here’s the working code I have tried in dartpad♥️ , incase someone searching for answers in dart.

void main() {
  RegExp exp = new RegExp(r"[0-9]+(.[0-9])?(GB|MB|gb|mb)");
  String str =Uri.decodeComponent(
      "0-%20Giri%20(2004)%5bTamil%201080p%20HD%20AVC%20-%20x264%20-%207.6GB%5d.mkv&tr=http%3a%2f%2fbt4");
  String match = exp.stringMatch(str);

  print(match);
}

Output:
7.6GB

One Answer

regex: [0-9]+(.[0-9]{1,2})?(GB|MB|gb|mb)

I didn't realize that this was a flutter/dart question and already developed a python solution. So I am posting the python solution.

import re
from urllib.parse import unquote

magnet = "0-%20Giri%20(2004)%5bTamil%201080p%20HD%20AVC%20-%20x264%20-%207.6GB%5d.mkv&tr=http%3a%2f%2fbt4"

size = re.search(r"[0-9]+(.[0-9]{1,2})?(GB|MB|gb|mb)", unquote(magnet)).group()

print(size)

Output: 7.6GB

Answered by Vishal Singh on January 1, 2022

Add your own answers!

Related Questions

std::map::operator[] is more efficient than std::map::insert?

1  Asked on December 27, 2020 by eddieipeace

   

Splitting a list (?)

1  Asked on December 27, 2020 by superannuated

   

Python Scrapy how to save data in different files

1  Asked on December 27, 2020 by silver-flash

   

JS get random value from array and update array

2  Asked on December 27, 2020 by nicolas-schmit

     

Caught and declared exception in Java?

1  Asked on December 26, 2020 by hrvoje-t

   

IEnumerable and Recursion using yield return

8  Asked on December 26, 2020 by jamie-dixon

       

How to parse CSV with node.js?

2  Asked on December 26, 2020 by idarosa

         

Why this program with for loop give zero when y>5 and x=2

2  Asked on December 26, 2020 by vms

 

Null pointer exception. How my connection object is pointing to null

2  Asked on December 26, 2020 by monisha-ravi

     

How do I make contents in HTML by using css

0  Asked on December 26, 2020 by jaeseo-lee

   

How to show Toaster after logout

2  Asked on December 26, 2020

   

How to write to a csv within a pandas UDF in pyspark?

0  Asked on December 26, 2020 by codemaster2020

   

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP