guinness Posted November 18, 2009 Share Posted November 18, 2009 (edited) I normally find what I am looking for by searching the forum! But this is driving me crazy! At the moment I am using the script which will search the Source Code between 2 Strings "(and AutoItX) v" and " released" to display the Version number. What I am trying to determine is how I could I select the words around "3.0.0.0"?E.G. in Pseudo Code - I search the Source Code for 3.0.0.0- I then take 3.0.0.0 and find the left and right words wrapping it or before it reaches a <SPACE>If it has been posted before and you know the forum URL or search terms that would helpful. I have been using "StringBetween Reverse", "StringLeft -1", "StringRight -1", "StringBetween Choose Tags", "StringBetween", "Search Word And Words Around" - only a few I have used.#include <INet.au3> Global $Updated $Current_Version = "2.0.0.0" Update() Func Update() $Update_Source = _INetGetSource("http://www.autoitscript.com/autoit3/") If @error Then MsgBox(0, "Error", "No Connection To The Internet.") Else $Online_Version = StringStripWS(_StringBetween2($Update_Source, "(and AutoItX) v", " released"), 8) If @error Or StringIsAlpha($Online_Version) = 1 Then ;If The String Is Not Numerical Show An Error. This Is If The SourceCode Changes And The Tags Have Changed. MsgBox(0, "Error", "Failed To Retrieve Version Number.") Return $Updated = False Else Sleep(50) If $Online_Version > $Current_Version Then MsgBox(0, "Update", "New Version Number Available. It Is Now " & $Online_Version) Exit Else MsgBox(0, "Update", "This Is The Latest Version. It Is " & $Online_Version) Return $Updated = False EndIf EndIf EndIf EndFunc ;==>Update ; Found At http://www.autoitscript.com/forum/index.php?showtopic=89554&view=findpost&p=643708 Func _StringBetween2($Source, $From, $To) $X = StringInStr($Source, $From) + StringLen($From) $Y = StringInStr(StringTrimLeft($Source, $X), $To) Return StringMid($Source, $X, $Y) EndFunc ;==>_StringBetweenTwoThanks! - guiness Edited November 18, 2009 by GuiNesS UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
water Posted November 18, 2009 Share Posted November 18, 2009 AutoIt already offers this function. Please have a look at AutoUpdateIt.au3 in <Your program folder>\AutoIt3\Extras\AutoUpdateIt My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
guinness Posted November 18, 2009 Author Share Posted November 18, 2009 AutoIt already offers this function. Please have a look at AutoUpdateIt.au3 in <Your program folder>\AutoIt3\Extras\AutoUpdateItHi Water,Thanks for that but that was just an example for people to test, I am not creating an AutoIT Downloader. The same code would apply to any site that you want to show any changes to a certain word or number. The example you gave I see relies on a .dat/.ini file to be hosted on the developers site, which isn't always the case. I am more interested in taking a number and then finding the words that wrap around it.E.G. This is a Word I am interested in. So I search the Source Code/File for 'Word' and then display $Begin = "This is a " and $End = " I am interested in." so I can then use in _StringBetween2($Update_Source, $Begin, $End).Thanks g. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 18, 2009 Moderators Share Posted November 18, 2009 GuiNesS, I think this does what you are looking for: #include <Array.au3> #Include <String.au3> $sText = "This is a Word I am interested in" $sKey = "Word" $aArray = StringSplit($sText, $sKey, 1) _ArrayDisplay($aArray) $sNewText = "This is a New Word I am interested in" $aNewKey = _StringBetween($sNewText, $aArray[1], $aArray[2]) MsgBox(0, "Key", $aNewKey[0]) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 18, 2009 Moderators Share Posted November 18, 2009 (edited) If you're only looking for one word to the left and right each. #include <Array.au3> Global $s_data = "Some words before 3.0.0.0 after it" Global $s_find = "3.0.0.0" Global $a_sre = StringRegExp($s_data, "(\w+)\h+" & $s_find & "\h+(\w+)", 1) _ArrayDisplay($a_sre) Edit: Here is another method with a few choices. I didn't test the _GetBeforeAfter() function much, you may need to debug on your own: expandcollapse popup#include <Array.au3> Global $s_data = "A lot of text before phrase. Some words before 3.0.0.0 after it." Global $s_find = "3.0.0.0" Global $s_strip = StringRegExpReplace($s_data, "(?s)(.*?(?:[[:punct:]]|\s)*)([\w\h]+" & $s_find & "[\w+\h]+)((?:\z|[[:punct:]].*?\z|\s.*?\z))", "$2") ; If you want the whole phrase you can stop here: MsgBox(64, "Info: Stripped data", $s_strip) ; Here we can get all the words, but we won't know what is before or after Global $a_words_jumbled = StringRegExp(StringRegExpReplace($s_strip, "\h*" & $s_find & "\h*", " "), "(\w+)(?:\z|\h|[[:punct:]])*", 3) _ArrayDisplay($a_words_jumbled) ; If you want to separate before words and after words into two different arrays, you could something like Global $a_words_separated = StringRegExp($s_strip, "(" & $s_find & "|\w+)(?:\z|\h|[[:punct:]])*", 3) Global $a_before_find[1], $a_after_find[1] _GetBeforeAfter($a_words_separated, $s_find, $a_before_find, $a_after_find) If IsArray($a_before_find) Then _ArrayDisplay($a_before_find, "Before find") Else MsgBox(64, "Info", "No before words") EndIf If IsArray($a_after_find) Then _ArrayDisplay($a_after_find, "After find") Else MsgBox(64, "Info", "No after words") EndIf Func _GetBeforeAfter($a_sre, $s_find, ByRef $a_before, ByRef $a_after) ReDim $a_before[UBound($a_sre)] ReDim $a_after[UBound($a_sre)] Local $i_before = 0, $i_after = 0, $i_found Local $i_ubound = UBound($a_sre) - 1 For $i = 0 To $i_ubound If $a_sre[$i] = $s_find Then If $i = 0 Then $a_before = "" $i_found = $i + 1 ExitLoop EndIf $a_before[$i_before] = $a_sre[$i] $i_before += 1 Next If $i_found >= $i_ubound Then ReDim $a_before[$i_before + 1] $a_after = "" Return EndIf For $i = $i_found To $i_ubound $a_after[$i_after] = $a_sre[$i] $i_after += 1 Next If IsArray($a_before) Then ReDim $a_before[$i_before] EndIf ReDim $a_after[$i_after] Return EndFunc Edited November 18, 2009 by SmOke_N code tags Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
guinness Posted November 18, 2009 Author Share Posted November 18, 2009 (edited) Dear Melba23 & SmOke_NThanks very much for your Examples something to look through. I think the one which best suits my needs is SmOke_N's final example. I have tweaked the original by adding _ArrayToString so I can then use in the _StringBetween function. I also did another search and came across an Old Thread in which you (SmOke_N) touched on _StringBetween. I didn't mention that StringRegExp is not my strongest point so I will be sitting down and reading this tonight .One final question I have on the below code is at the moment the expression is limited to Letters and Numbers how would I go about including HTML Syntax and taking the Before text even if it ends with a punctuation mark? E.G. <> & A lot of text before phrase. Some words before. 3.0.0.0 after it.I want to create enough data because if I have "The version is: " & "Number" it might appear more than once in the data (ChangeLog page for example).I thought it might be this for including HTML syntax? But it didn't work.Global $s_strip = StringRegExpReplace($s_data, "(?s)(.*?(?:[[:punct:]]|\s)*)([.*\h]+" & $s_find & "[.*+\h]+)((?:\z|[[:punct:]].*?\z|\s.*?\z))", "$2") Global $a_words_separated = StringRegExp($s_strip, "(" & $s_find & "|.*+)(?:\z|\h|[[:punct:]])*", 3)expandcollapse popup#include <Array.au3> Global $s_data = "A lot of text before phrase. Some words before 3.0.0.0 after it." Global $s_find = "3.0.0.0" Global $s_strip = StringRegExpReplace($s_data, "(?s)(.*?(?:[[:punct:]]|\s)*)([\w\h]+" & $s_find & "[\w+\h]+)((?:\z|[[:punct:]].*?\z|\s.*?\z))", "$2") ; If you want to separate before words and after words into two different arrays, you could something like Global $a_words_separated = StringRegExp($s_strip, "(" & $s_find & "|\w+)(?:\z|\h|[[:punct:]])*", 3) Global $a_before_find[1], $a_after_find[1] _GetBeforeAfter($a_words_separated, $s_find, $a_before_find, $a_after_find) If IsArray($a_before_find) Then ;_ArrayDisplay($a_before_find, "Before find") MsgBox(64, "Info", _ArrayToString($a_before_find, " ")) Else MsgBox(64, "Info", "No before words") EndIf If IsArray($a_after_find) Then ;_ArrayDisplay($a_after_find, "After find") MsgBox(64, "Info", _ArrayToString($a_after_find, " ")) Else MsgBox(64, "Info", "No after words") EndIf Func _GetBeforeAfter($a_sre, $s_find, ByRef $a_before, ByRef $a_after) ReDim $a_before[UBound($a_sre)] ReDim $a_after[UBound($a_sre)] Local $i_before = 0, $i_after = 0, $i_found Local $i_ubound = UBound($a_sre) - 1 For $i = 0 To $i_ubound If $a_sre[$i] = $s_find Then If $i = 0 Then $a_before = "" $i_found = $i + 1 ExitLoop EndIf $a_before[$i_before] = $a_sre[$i] $i_before += 1 Next If $i_found >= $i_ubound Then ReDim $a_before[$i_before + 1] $a_after = "" Return EndIf For $i = $i_found To $i_ubound $a_after[$i_after] = $a_sre[$i] $i_after += 1 Next If IsArray($a_before) Then ReDim $a_before[$i_before] EndIf ReDim $a_after[$i_after] Return EndFunc ;==>_GetBeforeAfterI thought this project would be easy, maybe this is the one that got away this time!!Thanks. g. Edited November 18, 2009 by GuiNesS UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 19, 2009 Moderators Share Posted November 19, 2009 I think it would be much easier and less time consuming ( for you and those willing to help ), if you'd provide an actual html.txt/url, and an "exact" String/Array of what you would hope the output to be from that html.txt/url. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
guinness Posted November 19, 2009 Author Share Posted November 19, 2009 Okay example sites: http://www.mozilla.com/en-US/firefox/ 3.5.5 is between "firefox/" and "/" http://www.softperfect.com/products/lspro/ 8.4.1 is between "<p> " and " " The intention is for the user to enter the current version number of the software, then search the source code for the corresponding number and select the outer words that wrap the version number. An update can be initiated by the user to check any changes to the version number by using _StringBetween() and the outer words. The example you provided works flawlessly but if HTML syntax is before or after it will fail to provide the outer words. Thanks. g. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 19, 2009 Moderators Share Posted November 19, 2009 Okay example sites: http://www.mozilla.com/en-US/firefox/3.5.5 is between "firefox/" and "/"http://www.softperfect.com/products/lspro/8.4.1 is between "<p> " and " "The intention is for the user to enter the current version number of the software, then search the source code for the corresponding number and select the outer words that wrap the version number. An update can be initiated by the user to check any changes to the version number by using _StringBetween() and the outer words. The example you provided works flawlessly but if HTML syntax is before or after it will fail to provide the outer words.Thanks. g.And the expected string result for each of those url examples is? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
guinness Posted November 19, 2009 Author Share Posted November 19, 2009 I have a posted an example of the Input Parametres and Output Results. Thanks. g. expandcollapse popup#include <Array.au3> #include <INet.au3> Global $a_before_find, $a_after_find _OuterStrip("http://www.autoitscript.com/autoit3/", "3.3.0.0") MsgBox(64, "Actual Result", '"' & $a_before_find & '"' & ' and ' & '"' & $a_after_find & '"' & '.') MsgBox(64, "Expected Result", '"v"' & ' and ' & '" released"' & '.') _OuterStrip("http://www.mozilla.com/en-US/firefox/upgrade.html", "3.5.5") MsgBox(64, "Actual Result", '"' & $a_before_find & '"' & ' and ' & '"' & $a_after_find & '"' & '.') MsgBox(64, "Expected Result", '"firefox/"' & ' and ' & '"/"') _OuterStrip("http://www.softperfect.com/products/lspro/", " 8.4.1") ;If the there is no space before the 8 it will result in an Error. MsgBox(64, "Actual Result", '"' & $a_before_find & '"' & ' and ' & '"' & $a_after_find & '"' & '.') MsgBox(64, "Expected Result", '"<p> "' & ' and ' & '"<SINGLE SPACE>"') Func _OuterStrip($s_dataURL, $s_find) $s_data = _INetGetSource($s_dataURL) $s_strip = StringRegExpReplace($s_data, "(?s)(.*?(?:[[:punct:]]|\s)*)([\w\h]+" & $s_find & "[\w+\h]+)((?:\z|[[:punct:]].*?\z|\s.*?\z))", "$2") Global $a_words_separated = StringRegExp($s_strip, "(" & $s_find & "|\w+)(?:\z|\h|[[:punct:]])*", 3) Global $a_before_find[1], $a_after_find[1] _GetBeforeAfter($a_words_separated, $s_find, $a_before_find, $a_after_find) If IsArray($a_before_find) Then $a_before_find = _ArrayToString($a_before_find, " ") If IsArray($a_after_find) Then $a_after_find = _ArrayToString($a_after_find, " ") EndFunc ;==>_OuterStrip ; Function created by SmOke_N Func _GetBeforeAfter($a_sre, $s_find, ByRef $a_before, ByRef $a_after) ReDim $a_before[UBound($a_sre)] ReDim $a_after[UBound($a_sre)] Local $i_before = 0, $i_after = 0, $i_found Local $i_ubound = UBound($a_sre) - 1 For $i = 0 To $i_ubound If $a_sre[$i] = $s_find Then If $i = 0 Then $a_before = "" $i_found = $i + 1 ExitLoop EndIf $a_before[$i_before] = $a_sre[$i] $i_before += 1 Next If $i_found >= $i_ubound Then ReDim $a_before[$i_before + 1] $a_after = "" Return EndIf For $i = $i_found To $i_ubound $a_after[$i_after] = $a_sre[$i] $i_after += 1 Next If IsArray($a_before) Then ReDim $a_before[$i_before] EndIf ReDim $a_after[$i_after] Return EndFunc ;==>_GetBeforeAfter UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 19, 2009 Moderators Share Posted November 19, 2009 (edited) String manipulation has to have a "specific" set of rules. What you're asking to receive is going to need specific rules for each site to get the absolute desired output.With the Firefox url as an example, there are like 5 or 6 specific 3.5.5 text values, and you're only wanting one specific value with no set of rules you've placed._StringBetween() ( You saw comments on it from me because I wrote it ) ... But, I'm not sure where this even comes into play with wanting to find the words before and after.So now after my ramble, I think you'll see I'm totally confused on what exactly you're trying to do, and how you would expect to limit the text you received before and after to something specific with no set rules for each of the sites.If this doesn't do it, then you're on your own or at the mercy of the other forum members:#include <Inet.au3> Global $a_word_before[1], $a_char_after[1] _GetGeneral("http://www.softperfect.com/products/lspro/", " 8.4.1", $a_word_before, $a_char_after) MsgBox(64, "Info", "Before Characters:" & @CRLF & $a_word_before[0] & @CRLF & @CRLF & "After Character:" & @CRLF & $a_char_after[0]) Func _GetGeneral($s_url, $s_find, ByRef $a_before, ByRef $a_after) Local $s_html = _INetGetSource($s_url) Local $s_pattern = "\v.*?(\W?\w+\W?)\Q" & $s_find & "\E([\W\w]).*?(?:\z|\v)" Local $a_data = StringRegExp($s_html, $s_pattern, 3) If @error Then Return SetError(1, 0, 0) Local $i_ubound = UBound($a_data) ReDim $a_before[1] $a_before[0] = $a_data[$i_ubound - 2] ReDim $a_after[1] $a_after[0] = $a_data[$i_ubound - 1] Return 1 EndFunc Edited November 19, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
guinness Posted November 20, 2009 Author Share Posted November 20, 2009 (edited) Thanks for the example code this is a great basis to start and good example for someone who requires practical examples of StringRegExp. At the moment I am designing a software monitoring program, which monitors any website (users decision) by verifying differences to the version number in the database file and on the website. At the moment the user has to manually select the outer tags/text of where the version number is located on the site, hence why I require _StringBetween() because I then run a function which compares the number on site to the version saved in their database file (see basic example in first post) so I was curious of how to automatically select the outer tags/text. I did try and search for a StringLeft that instead of goes left to right works from right to left (not StringRight) e.g. StringLeft(StringInStr("<title>Version 1.00</title>", "1.00"), -8) would result in "Version " or something along those lines. Milestones I will have to overcome as you have mentioned is more than one instance of the version number and expanding the outer tags, especially if <p> is next to the version number! Thanks. g. Edited November 20, 2009 by GuiNesS UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 20, 2009 Moderators Share Posted November 20, 2009 Sounds more like you need an AI for what you're trying to accomplish in the long run. Version updates/differences could be anywhere in the html or no where. And to base the outer text on the users knowledge of how html works is an insane project lol, I can see the email requests for help now! I believe you mentioned before that you thought this would be "simple", I see no "simple" method to obtain a true consistent flow of data return. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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