webjocky Posted January 28, 2011 Share Posted January 28, 2011 I've been playing with this for waay too long (5+ hours). Google & RegexBuddy haven't helped me yet, so I'm hoping someone with a bit of Regex experience with AutoIt syntax can help me figure out what I'm doing wrong. I need to match up to 5 (at least two) sets of up-to 5 digits, seperated by periods (12345.12345.12345.12345.12345) - software version numbers. I can only get the first two sets to return with what I have below. For this particular test, the result I'm expecting is "3.03.1366" but I can only get "3.03" to return. (I've got my error handling function commented out here so you can just copy/paste and run the script with nothing more). GetUpdates("CCleaner") Func GetUpdates($token) #include <IE.au3> $oIE = _IECreate ("http://www.filehippo.com/search?q=" & $token, 0, 0) $SiteText = _IEBodyReadText($oIE) ;~ If @error = 1 Then ErrorHandler(2) ElseIf @error = 2 Then ErrorHandler(3) EndIf $AnyFound = StringRegExp($SiteText, $token & "\s([0-9]{1,5}[.][0-9]{1,5})([.]?[0-9]{1,5})([.]?[0-9]{1,5})([.]?[0-9]{1,5})([.]?[0-9]{1,5})",1) If isArray($AnyFound) Then MsgBox(0, "Latest CCLeaner Version", $AnyFound[0]) Else ;~ ErrorHandler(2) EndIf _IEQuit ($oIE) EndFunc Driving me insane! The tiniest of things can ruin your day, or brighten your afternoon. Read it once, read it again, and pay attention. Then search the forums. If all else fails, ask somebody else. Link to comment Share on other sites More sharing options...
jchd Posted January 28, 2011 Share Posted January 28, 2011 Does this work better? #include <IE.au3> GetUpdates("CCleaner") Func GetUpdates($token) $oIE = _IECreate ("http://www.filehippo.com/search?q=" & $token, 0, 0) $SiteText = _IEBodyReadText($oIE) ;~ If @error = 1 Then ErrorHandler(2) ElseIf @error = 2 Then ErrorHandler(3) EndIf ConsoleWrite($SiteText & @LF) $AnyFound = StringRegExp($SiteText, $token & "\s?((?:\d{1,5})(?:\.\d{1,5}){1,4})",1) If isArray($AnyFound) Then MsgBox(0, "Latest CCLeaner Version", $AnyFound[0]) Else ;~ ErrorHandler(2) EndIf _IEQuit ($oIE) EndFunc 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
webjocky Posted January 28, 2011 Author Share Posted January 28, 2011 Does this work better? #include <IE.au3> GetUpdates("CCleaner") Func GetUpdates($token) $oIE = _IECreate ("http://www.filehippo.com/search?q=" & $token, 0, 0) $SiteText = _IEBodyReadText($oIE) ;~ If @error = 1 Then ErrorHandler(2) ElseIf @error = 2 Then ErrorHandler(3) EndIf ConsoleWrite($SiteText & @LF) $AnyFound = StringRegExp($SiteText, $token & "\s?((?:\d{1,5})(?:\.\d{1,5}){1,4})",1) If isArray($AnyFound) Then MsgBox(0, "Latest CCLeaner Version", $AnyFound[0]) Else ;~ ErrorHandler(2) EndIf _IEQuit ($oIE) EndFunc Exactly what I was looking for... now, I need to do some serious studies on regex. Thanks! The tiniest of things can ruin your day, or brighten your afternoon. Read it once, read it again, and pay attention. Then search the forums. If all else fails, ask somebody else. Link to comment Share on other sites More sharing options...
jchd Posted January 28, 2011 Share Posted January 28, 2011 You see I've been loosing my hair with regexps a little before you, but it's your turn now 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
GEOSoft Posted January 28, 2011 Share Posted January 28, 2011 (edited) jchd gave you what I think is the best expression to do what you want but I would have made a simple change to allow for case insensitive in the event someone enters ccleaner or CCLEANER or Ccleaner &etc.Also remember you could do it with StringRegExpReplace()To add case insensitive to the expression by jchd just change$token & "\s?((?:\d{1,5})(?:\.\d{1,5}){1,4})"to"(?i)" & $token & "\s?((?:\d{1,5})(?:\.\d{1,5}){1,4})"$sVersion = StringRegExpReplace($SiteText, "(?is).*ccleaner\s?((?:\d{1,5})(?:\.\d{1,5}){1,4}).*", "$1") If @Extended Then MsgBox(0, "Latest CCLeaner Version", $sVersion) Else ;~ ErrorHandler(2) EndIf Edited January 28, 2011 by GEOSoft 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 More sharing options...
jchd Posted January 28, 2011 Share Posted January 28, 2011 You're right George. I knew you lost your hair as well but this proves you didn't loose your brain like I did. More seriously and more toward OP problem, there may be software around having versions numbers using alpha as well, like 3.5.9a in which case a more subtle approach is needed. OTOH I didn't notice such weird numbering in any recent product. 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
GEOSoft Posted January 28, 2011 Share Posted January 28, 2011 Right you are although like you I haven't seen anyone using alpha in the version string for quite a while now. Without testing it I don't think a-z would be too much of a problem anyway since we know from experience it is always the last character in the version and in the page the OP is using there is always a space (\h or \v) following the version. 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now