TransWikia.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!

Ask a Question

Get help from others!

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