Useful RegEx to extract information from a text-only TQDM stream. I personally found this useful to extract progress data from a Python child process and use it to update a progress bar in my front-end Electron UI.
The RegEx:
(.*): *(\d+%).*(\d+\/\d+) +\[(\d+:\d+)<(\d+:\d+), +(\d+.\d+.*\/s)\]
Capture Groups:
- Label
- Percent Complete
- Count (i.e. 13/15)
- Time Elapsed
- Estimated Time Remaining
- Rate
Capture Groups Example (credit: regexr.com):
Example JS Usage:
const stringToTest = '' // Whatever string you're testing
const regex = /(.*): *(\d+%).*(\d+\/\d+) +\[(\d+:\d+)<(\d+:\d+), +(\d+.\d+.*\/s)\]/
const match = stringToTest.match(tqdmRegex);
const label = match[1];
const percent = match[2];
const count = match[3]; // Only the percent and label are really "necessary" - these are still available for easy addition in the future
const elapsed = match[4];
const left = match[5];
const rate = match[6];
console.log(`${label}: ${percent} (${elapsed} elapsed, ${left} left, ${rate}/s)`)