Mat Posted November 29, 2013 Share Posted November 29, 2013 Basically StringMid, but without the last parameter. AutoIt Project Listing Link to comment Share on other sites More sharing options...
jaberwacky Posted January 3, 2014 Share Posted January 3, 2014 (edited) Found a func that I forgot to submit from a while back. Returns an array of strings between two regular expressions. You could have wrote it yourself with your eyes closed. #include <String.au3> Func _RegExpStringBetween(Const $test, Const $start_pattern, Const $end_pattern) Local Const $start = StringRegExp($test, $start_pattern, 1)[0] If @error Then Return SetError(1, 0, False) Local Const $end = StringRegExp($test, $end_pattern, 1)[0] If @error Then Return SetError(2, 0, False) Local Const $string_between = _StringBetween($test, $start, $end) Return @error ? SetError(3, 0, False) : $string_between EndFunc Edited January 3, 2014 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Tlem Posted January 3, 2014 Share Posted January 3, 2014 Hi jaberwocky6669, great function. If I open my eyes, based to your function and source code of _StringBetween(), I can wrote this one, for older version of AutoIt and without including File.au3. Func _RegExpStringBetween($sString, $sStart, $sEnd, $fCase = False) $sStart = StringRegExp($sString, $sStart, 1)[0] If @error Then Return SetError(1, 0, False) $sEnd = StringRegExp($sString, $sEnd, 1)[0] If @error Then Return SetError(2, 0, False) ; Set correct case sensitivity If $fCase = Default Then $fCase = False EndIf Local $sCase = "(?is)" If $fCase Then $sCase = "(?s)" EndIf ; If you want data from beginning then replace blank start with beginning of string $sStart = $sStart ? "\Q" & $sStart & "\E" : "\A" ; If you want data from a start to an end then replace blank with end of string $sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z" Local $aReturn = StringRegExp($sString, $sCase & $sStart & "(.*?)" & $sEnd, 3) If @error Then Return SetError(3, 0, 0) Return $aReturn EndFunc jaberwacky 1 Best Regards.Thierry Link to comment Share on other sites More sharing options...
guinness Posted January 3, 2014 Share Posted January 3, 2014 Tlem, There is no difference between the two. If you mean you version is for pre v3.3.10.0 then I am afraid your version will fail because you're using the ternary operator. Well _StringBetween() is, which is what you just stripped out. 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...
Tlem Posted January 3, 2014 Share Posted January 3, 2014 Yes guinness. It's what I said : based to your function and source code of _StringBetween() It's just that this version of the snippet doesn't include external functions, use the same structure and naming than _StringBetween() and add the case sensitive option ... If this function is intended to be included in String.au3, jaberwocky6669 version is more simple. Best Regards.Thierry Link to comment Share on other sites More sharing options...
guinness Posted January 3, 2014 Share Posted January 3, 2014 Stripping includes is never a good idea. Period. 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...
Tlem Posted January 3, 2014 Share Posted January 3, 2014 (edited) Like you want guinness. Can being I would have had to propose this improvement for adding case sensitivity : #include <String.au3> Func _RegExpStringBetween(Const $test, Const $start_pattern, Const $end_pattern, $fCase = False) $fCase = ($fCase = Default) ? False : $fCase $sCase = ($fCase = True) ? "(?s)" : "(?is)" Local Const $start = StringRegExp($test, $sCase & $start_pattern, 1)[0] If @error Then Return SetError(1, 0, False) Local Const $end = StringRegExp($test, $sCase & $end_pattern, 1)[0] If @error Then Return SetError(2, 0, False) Return @error ? SetError(3, 0, False) : _StringBetween($test, $start, $end, $fCase) EndFunc If we count the include, only 1 line difference between this : Func _RegExpStringBetween2($sString, $sStart, $sEnd, $fCase = False) $fCase = ($fCase = Default) ? False : $fCase $sCase = ($fCase = True) ? "(?s)" : "(?is)" $sStart = StringRegExp($sString, $sStart, 1)[0] If @error Then Return SetError(1, 0, False) $sEnd = StringRegExp($sString, $sEnd, 1)[0] If @error Then Return SetError(2, 0, False) $sStart = $sStart ? "\Q" & $sStart & "\E" : "\A" $sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z" Return @error ? SetError(3, 0, False) : StringRegExp($sString, $sCase & $sStart & "(.*?)" & $sEnd, 3) EndFunc Not a lot of difference between both, but the second is 30% more efficients and have no include. ^^ Maybe can we optimize the first part of the code with ternary operator. Edited January 3, 2014 by Tlem Best Regards.Thierry Link to comment Share on other sites More sharing options...
iamtheky Posted January 3, 2014 Share Posted January 3, 2014 (edited) Wait, wait. He wrote a version that does not use the ternary and so is backwards compatible, so no need for the stringbetween, so no need for the include? Stripping includes seems to be a great idea if they are unnecessary, or did i misunderstand post #123 was accomplishing? If you mean you version is for pre v3.3.10.0 then I am afraid your version will fail because you're using the ternary operator. Well _StringBetween() is, which is what you just stripped out. Does that quote say:. "Yours is for older versions, but it will fail because it uses the ternary operator, well you are not but this function does, and you are not using that function...." ? Edited January 3, 2014 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Tlem Posted January 3, 2014 Share Posted January 3, 2014 @boththose Unfortunately, as guinness said, my first proposal was not backwards compatible, due to this 2 lines : ; If you want data from beginning then replace blank start with beginning of string $sStart = $sStart ? "\Q" & $sStart & "\E" : "\A" ; If you want data from a start to an end then replace blank with end of string $sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z" Best Regards.Thierry Link to comment Share on other sites More sharing options...
guinness Posted January 3, 2014 Share Posted January 3, 2014 (edited) That sentence I wrote was in the morning. What I meant to say is Tlem stated that the new version was designed for "older versions" of AutoIt, but anything before v3.3.10.0 doesn't use the ternary operator and thus his function will fail, hence it's not written for older versions of AutoIt as stated. By stripping _StringBetween() they are in affect forcing people to upgrade their version of AutoIt and what happens if there is a bug in _StringBetween() in future versions? Will Tlem remember to update this snippet? jaberwocky6669''s version was correct as it allows for flexibility in future versions of AutoIt. I am sometimes surprised at how people don't look at the bigger picture. Imagine I copy that function into a script which uses _StringBetween(), isn't that just duplicating code? OK, so it's 3 lines, but if we did that for every function which used _StringBetween() it would be a maintenance nightmare and then people would have something to complain about the filesize. Am I the only one that can see stripping includes for the sake of not having an include line as being a bad thing? Edited January 3, 2014 by guinness 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...
iamtheky Posted January 3, 2014 Share Posted January 3, 2014 Am I the only one that can see stripping includes for the sake of not having an include line as being a bad thing? Nope, I misunderstood the communication and was simply an aside while i was searching threads attempting to understand ternary better. thank you both, ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
jaberwacky Posted January 3, 2014 Share Posted January 3, 2014 (edited) I tend to agree that having an include is not a bad thing. The functionality is there to be used. There are also programs that strip out everything that isn't used in the include. However, I am intrigued by Tlem's version with the case stuff. Maybe we should work on an uber function? Just looked at the source and saw that it was already there. Durrrr. Edited January 3, 2014 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Tlem Posted January 3, 2014 Share Posted January 3, 2014 guinness you right. @boththose If you want a backwards compatible _RegExpStringBetween() function, try this one : Func _RegExpStringBetween($sString, $sStart, $sEnd, $fCase = False) ; Set correct case sensitivity If $fCase = Default Then $fCase = False EndIf Local $sCase = "(?is)" If $fCase Then $sCase = "(?s)" EndIf $sStart = StringRegExp($sString, $sStart, 1)[0] If @error Then Return SetError(1, 0, False) $sEnd = StringRegExp($sString, $sEnd, 1)[0] If @error Then Return SetError(2, 0, False) ; If you want data from beginning then replace blank start with beginning of string If $sStart = "" Then $sStart = "\A" Else $sStart = "\Q" & $sStart & "\E" EndIf ; If you want data from a start to an end then replace blank with end of string If $sEnd = "" Then $sEnd = "\z" Else $sEnd = "(?=\Q" & $sEnd & "\E)" EndIf Local $aReturn = StringRegExp($sString, $sCase & $sStart & "(.*?)" & $sEnd, 3) If @error Then Return SetError(3, 0, 0) Return $aReturn EndFunc iamtheky 1 Best Regards.Thierry Link to comment Share on other sites More sharing options...
guinness Posted January 3, 2014 Share Posted January 3, 2014 If it's worth adding to the UDFs I will consider it at least. But to me _StringBetween() looks feature complete. 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...
jchd Posted January 4, 2014 Share Posted January 4, 2014 (edited) A different approach: Func _RegExpStringBetween(Const $test, $start_pattern, Const $end_pattern) $start_pattern = StringRegExpReplace($start_pattern, "((?:\\\\)*)(\\Q.*?\\E)", "\1") StringRegExpReplace($start_pattern, "(?x) (?:\\\\)* \K (?<!\\) ( \( (?= \?< | \?' | \?P< ) | \( (?! \* | \? [-:\|>#\w=!+&(] | \? <= | \? <! | \? P= | \? P> ) )", "") Local $group = @extended Local $string_between = StringRegExp($test, $start_pattern & '(.*?)' & $end_pattern, 1) If @error Then Return SetError(1, 0, False) Else Return $string_between[$group] EndIf EndFunc Edited January 4, 2014 by jchd Tlem, iamtheky and jaberwacky 3 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...
czardas Posted January 4, 2014 Share Posted January 4, 2014 My first thought - doesn't regexp already cover _StringBetween() functionality? jaberwacky 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jaberwacky Posted January 4, 2014 Share Posted January 4, 2014 My first thought - doesn't regexp already cover _StringBetween() functionality? Ouch. I guess it does huh? Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jchd Posted January 4, 2014 Share Posted January 4, 2014 Of course it does! It also has the _big_ advantage of not requiring parameter validation. See my code above why this is preferable! 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...
Tlem Posted January 5, 2014 Share Posted January 5, 2014 (edited) My first thought - doesn't regexp already cover _StringBetween() functionality? Yes it does, but like a lot of snippets on this topic, the goal is to simplify the writing of what is searching to do. Just some examples taken on this wonderful topic : _StripQuotes(), _ParseDateString(), _IsFileNewer(), use StringRegExpReplace() and some lines of code. And what about _IsChecked(). Isn't it more easy to use _IsChecked($control) than BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED ? If a beginner (or not) want to extract datas between 2 strings in regex pattern, I think that it's more easy to use _RegExpStringBetween($sString, $sPatternStart, $sPatternEnd, $fCase) instead of a combination of StringRegExp($sString, $sPattern [, flag = 0 [, offset = 1]]) and/or StringRegExpReplace($sString, $sPattern, $sReplace [, count = 0]) adapted for the circumstance ... Like you said in another post, >it's a small tweaks to the function _StringBetween() or StringRegExp(). Edited January 5, 2014 by Tlem Best Regards.Thierry Link to comment Share on other sites More sharing options...
czardas Posted January 6, 2014 Share Posted January 6, 2014 I understand and don't disagree with you. I also think that function of mine can be improved (I'll look at it again). In terms of StringRegExpBetween() , I think users who are at the stage of handling regular expressions should learn to use back referencing ASAP. operator64 ArrayWorkshop 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