Jump to content

StringRegExpReplace


Recommended Posts

Having trouble extracting the time from a string. Here's an example of the string at a certain point in the progress:

[ 73% ] Applying progress: 11:31 mins remaining

I want to be able to extract the time from that line (11:31 in this case) and populate a GUI label with it as it's changing. I've been trying to figure out how to make a regular expression that works, but nothing is getting just the time itself. I'd like to be able to get the time if it's HH:MM:SS. Ideally I'd like to grab the "mins" or secs" text afterwards too.

Can someone help me with the correct expression?

Sample code so far:

$fLine = "[  73% ] Applying progress: 11:31 mins remaining"
$fPercentage = StringRegExpReplace($fLine,"^.*\[\s*(\d+)%\s*\].*$","$1"); This gets the percentage just fine.
$fTimeRemaining = StringRegExpReplace($fLine,"^.*\[\s*(\d+)%\s*\].*$","$1:$2"); This isn't getting me the time (which could be HH:MM:SS)
msgbox(0,"Time Remaining",$fTimeRemaining)
Link to comment
Share on other sites

$sLine = "[ 73% ] Applying progress: 11:31 mins remaining"
$sTime = StringRegExpReplace($sLine, "(?m:^).+?:\h([\d:]+)\h.+", "$1")

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

This should do:

$fLine = "[  73% ] Applying progress: 11:31 mins remaining"
$fPercentage = StringRegExpReplace($fLine,"^.*\[\s*(\d+)%\s*\].*$","$1"); This gets the percentage just fine.
$fTimeRemaining = StringRegExpReplace($fLine,"^.*?(\d+:)?(\d+:\d+).*$","$1$2"); This isn't getting me the time (which could be HH:MM:SS)
msgbox(0,"Time Remaining",$fTimeRemaining)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

$sLine = "[ 73% ] Applying progress: 11:31 mins remaining"
$sTime = StringRegExpReplace($sLine, "(?m:^).+?:\h([\d:]+\h.+)", "$1")

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

#include <Array.au3>

$fLine = "[  73% ] Applying progress: 11:31 mins remaining"
$aPieces = StringRegExp($fLine, "\[\s*(\d+)%\s*\]\s*\b([^:]*):\s*((?:\d+:)?(?:\d+:\d+))\s*(.*)", 1)
_ArrayDisplay($aPieces)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...