water Posted December 8, 2013 Share Posted December 8, 2013 Faster: agreed, simpler because shorter code: agreed, easily understandable: it depends. If you are a fan of regex then yes, if not (like me) then a While/Wend construct is easier to understand IMHO. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
mikell Posted December 8, 2013 Share Posted December 8, 2013 I would obviously not say 'easily understandable' about all regexes, but here in this particular case Malkey's regex is basic and could be a pretty good example for regex beginners Not to be a regex fan should not mean avoid regex Link to comment Share on other sites More sharing options...
water Posted December 8, 2013 Share Posted December 8, 2013 I very rarely see the need for a RegExp in my scripts so I avoid to get my feet wet with them. I'm sure I forget most of what I know about RegExp till the next time I need them plus I will not be able to easily understand what I have written some months ago. As speed is no issue most of the time I'm happy with the While/WEnd alternative But who knows ... My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
czardas Posted December 8, 2013 Share Posted December 8, 2013 Edit: Changed reg. exp. from:- '$sString = StringRegExpReplace($sString, "(.{0,59})(h)", "1" & @CRLF)' to '$sString = StringRegExpReplace($sString, "(.{1,59})(h+|$)", "1" & @CRLF)' The last line wasn't formating correctly. Okay, you put $ where I would have put z '$sString = StringRegExpReplace($sString, "(.{1,59})(h+|z)", "1" & @CRLF) operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Malkey Posted December 9, 2013 Share Posted December 9, 2013 Malkey - I think you just need to put z somewhere in that regexp. Test for end of text OR space. Nice regexp BTW. You were right about this. Okay, you put $ where I would have put z '$sString = StringRegExpReplace($sString, "(.{1,59})(h+|z)", "1" & @CRLF) Now I know what to get you for Christmas - a backslash z. Link to comment Share on other sites More sharing options...
czardas Posted December 9, 2013 Share Posted December 9, 2013 LOL, Merry christmas to you Malkey. I give you a christmas card with z+ operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
dickjones007 Posted December 9, 2013 Author Share Posted December 9, 2013 I very rarely see the need for a RegExp in my scripts so I avoid to get my feet wet with them. I'm sure I forget most of what I know about RegExp till the next time I need them plus I will not be able to easily understand what I have written some months ago. As speed is no issue most of the time I'm happy with the While/WEnd alternative But who knows ... very good point. im just like that also. i consider myself a mid range beginner at autoit so a While/Wend is the way to go for me. Link to comment Share on other sites More sharing options...
jchd Posted December 9, 2013 Share Posted December 9, 2013 Don't be shy and jump over the limits you impose on yourself. Not only this will make you better, more comprehensive persons , but it will also help you in everydays non-programming work since regexps are available in editors, word processors, almost all search tools, etc. 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 December 9, 2013 Share Posted December 9, 2013 I find regexp indispensable, although admittedly my learning runs on a need to know basis due to personal time constraints. I say get your hands dirty and take that engine apart. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
guinness Posted December 9, 2013 Share Posted December 9, 2013 I use regular expressions pretty much 4/5 times a week. Like the other day I needed to parse a script of mine to replace $hVar( with $hVar.Item( (a Scripting.Dictionary Object), this was done with a regular expression which I wrote pretty quickly. I think it was StringRegExpReplace($sData, '($w+)(', '1.Item(') if I remember correctly. 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...
dickjones007 Posted December 10, 2013 Author Share Posted December 10, 2013 (edited) someday ill surely get to learn regexp but now it just looks to me like swearing from a comic book is there any great tutorial for it or something? (other than autoit help section) --answer to self: there is good tutorial in jchd's signature Edited December 10, 2013 by dickjones007 czardas 1 Link to comment Share on other sites More sharing options...
guinness Posted December 10, 2013 Share Posted December 10, 2013 Check in Chat, I posted a video the other day about regular expressions or "ASCII Puke" as it's sometimes called. dickjones007 1 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...
dickjones007 Posted December 10, 2013 Author Share Posted December 10, 2013 i love the video thank you Link to comment Share on other sites More sharing options...
czardas Posted December 10, 2013 Share Posted December 10, 2013 (edited) it just looks to me like swearing from a comic book What a brilliant idea! You are a genius. Edited December 10, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
dickjones007 Posted December 10, 2013 Author Share Posted December 10, 2013 LOL did i help you in anyway or do i just amuse you Link to comment Share on other sites More sharing options...
czardas Posted December 10, 2013 Share Posted December 10, 2013 No I'm serious. Ascii Puke comics where all the characters speak in code. Every speech bubble contains a small program which has some relevance to the story. You are a genius. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
kylomas Posted December 10, 2013 Share Posted December 10, 2013 @Malkey - I don't understand the second capturing group. $sString = StringRegExpReplace($sString, "(.{1,59})(\h+|$)", "\1" & @CRLF) This seems to work, what am I missing? $sString = StringRegExpReplace($sString, "(.{1,59})\h+|$", "\1" & @CRLF) @dickjones007 - apologies for intrusion... kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted December 10, 2013 Share Posted December 10, 2013 The parentheses are grouping, without them the OR gets an other signification Local $sString = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum dolores et ea rebum end.' $res = StringRegExpReplace($sString, "(.{1,59})(\h+|$)", "$1" & @CRLF) Msgbox(0,"", $res) $res = StringRegExpReplace($sString, "(.{1,59})\h+|$", "$1" & @CRLF) Msgbox(0,"", $res) Link to comment Share on other sites More sharing options...
kylomas Posted December 10, 2013 Share Posted December 10, 2013 Thanks mikell, I see that the match is different at end-of-string but don't understand why. I'm going to have to go re-read the doc in JCHD's sig. Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jchd Posted December 10, 2013 Share Posted December 10, 2013 kylomas, Think of | as a higher priority operator bounded by groups (). Hence the second RE is (.{1,59})h+ OR $ while the first is (.{1,59}) followed by (h+ OR $) The parts in red are conceptual, obviously. 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...
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