kylomas Posted October 26, 2012 Share Posted October 26, 2012 (edited) Good Morning, Given the following 1 12 123 9 98 987 11 *- there is a space at the beginning and end of the string (\d{1,2}) and (\d\d?) return the same result. Are these stmts functionally equivalent or is this a coincidence the pattern I am using? If they are functionally equivalent, when is one preferred over another? Also, The first "12" is not reported a a match. Is this because the space before it is "consumed" by the previous match? Thanks, kylomas Note - I am reading through the tutorials cited by various members, including jchd, however, there are as many unanswered questions as answered questions! Edited October 26, 2012 by 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...
Moderators Melba23 Posted October 26, 2012 Moderators Share Posted October 26, 2012 kylomas,Disclaimer: My opinion only and I am far from expert in SREs! Are these stmts functionally equivalentYes.Is this because the space before it is "consumed" by the previous match?It might be. What are you using as a pattern and what exactly are you trying to pull from this string? All the 1/2 digit numbers? All 1/2 digit combinations preceded by a space? All 1/2 digit combinations preceded and followed by a space? 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...
Robjong Posted October 26, 2012 Share Posted October 26, 2012 (edited) Hi,yes these are equal."(d{1,2})"d - matches any didgit {1,2} - tells the engine to match the previous part ( d ) one or two times."(dd?)"d - matches any didgit d - matches any didgit ? - tells the engine to match the previous part ( the second d ) zero or one times.So they both allow for one or two digits, and there are a whole lot of other ways to reach the same outcome.Edit: You might also want to check out the example I gave here: Edited October 26, 2012 by Robjong Link to comment Share on other sites More sharing options...
guinness Posted October 26, 2012 Share Posted October 26, 2012 Isn't the first one more optimal? 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...
Robjong Posted October 26, 2012 Share Posted October 26, 2012 (edited) Not really, they should result in the same logic in the engine, but to read the expression one might prefer the former.The matches can be one or two digits. Once the engine encounters a digit the backtrack position is stored.The engine then goes on to see if it can match a second digit right after the first match, stores the result if it is and continues from there.If not the engine backtracks to the last known position and saves the result and continues from there.Edit: added explanation. Edited October 26, 2012 by Robjong Link to comment Share on other sites More sharing options...
jdelaney Posted October 26, 2012 Share Posted October 26, 2012 Both will return values that you probably do not expect...such as when you have 3 digits, it will be broken up into a 2digit integer and a 1digit integer. You need to consider string begin and string ends, or include all following digits: (d+) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Robjong Posted October 26, 2012 Share Posted October 26, 2012 Both will return values that you probably do not expect...such as when you have 3 digits, it will be broken up into a 2digit integer and a 1digit integer.You need to consider string begin and string ends, or include all following digits: (d+)Excatly, but this might not be relevant to the OP. Btw. This is excatly what the example I linked to shows. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 26, 2012 Moderators Share Posted October 26, 2012 jdelaney,You need to consider string begin and string endsI quite agree with you, which is why I asked the OP what he actually expects as a return. M23 jdelaney 1 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...
jdelaney Posted October 26, 2012 Share Posted October 26, 2012 (edited) whoops, misquoted...boundaries are key: #include <Array.au3> $a = StringRegExp ( "1 12 123 9 98 987 11", "b(d{1,2})b", 3 ) _ArrayDisplay ( $a ) Edited October 26, 2012 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
kylomas Posted October 26, 2012 Author Share Posted October 26, 2012 @all - Thanks for the responses. My first question is answered. My second question cannot be answered because I fucked up. The pattern should have read( d{1,2} ). The pattern, entered correctly, is returning "12" and "9". Is that because of this from RobjongThe matches can be one or two digits. Once the engine encounters a digit the backtrack position is stored. The engine then goes on to see if it can match a second digit right after the first match, stores the result if it is and continues from there. If not the engine backtracks to the last known position and saves the result and continues from there. ??????? Again, thanks for the prompt replies and apologies for the screw up... 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...
jdelaney Posted October 26, 2012 Share Posted October 26, 2012 help us out...what EXACTLY are you expected to return from1 12 123 9 98 987 11put it like:1) #2) ##3) etc IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
kylomas Posted October 26, 2012 Author Share Posted October 26, 2012 jdelaney,I am trying to get my arms around this cryptic language. I believe that Robjong answered this question The first "12" is not reported a a match. Is this because the space before it is "consumed" by the previous match? or, am I missing something again!Apologies, again,for posting the regexp incorrectly, and, thank you for your time!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...
Moderators Melba23 Posted October 26, 2012 Moderators Share Posted October 26, 2012 kylomas, Please post what you want as a return from the RegEx as both jdelaney and I asked above - until then we cannot really answer your question! 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...
kylomas Posted October 26, 2012 Author Share Posted October 26, 2012 M23, Apologies if I am not being clear enough. My questions were about syntax and behavior of regexp and have been answered. Thank you all for your time. kylomas P.S. If I seem to be generally confused, it is because I am! I blame too many regexp tutorials in the last 48 hours for this! 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...
Moderators Melba23 Posted October 26, 2012 Moderators Share Posted October 26, 2012 kylomas, If you are happy that your questions have been answered, then fine.... 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...
jmosley708 Posted October 28, 2012 Share Posted October 28, 2012 I have a regexp search that works everywhere but in autoit3 it goes like this: $sd = "Sent by Team:SYSADMIN User:jm5751" $r = StringRegExp($sd, '([a-z]{2}d{3})(d|[a-z])',01) ConsoleWrite('user id: ' & $r[0] & @crlf) I can get the jm575 but I can't get the 1 after or the alpha if there is one. What can I do to fix this? Thanks Link to comment Share on other sites More sharing options...
Malkey Posted October 28, 2012 Share Posted October 28, 2012 If the pattern in the second capture group matches text in the test string, that text will be in the second element of the returned array. $sd = "Sent by Team:SYSADMIN User:jm5751" $r = StringRegExp($sd, '([a-z]{2}d{3})([da-z]?)', 1) ConsoleWrite('user id: ' & $r[0] & $r[1] & @CRLF) @jmosley You should have started another thread (your own thread) instead of appending to this thread. Link to comment Share on other sites More sharing options...
jmosley708 Posted October 28, 2012 Share Posted October 28, 2012 Thanks, that worked. How do I start a new thread? Link to comment Share on other sites More sharing options...
caleb41610 Posted October 28, 2012 Share Posted October 28, 2012 (edited) Thanks, that worked. How do I start a new thread?edit: never mind, I'm up too late.. Edited October 28, 2012 by caleb41610 Multi-Connection TCP Server Link to comment Share on other sites More sharing options...
Malkey Posted October 29, 2012 Share Posted October 29, 2012 ....@jmosleyYou should have started another thread (your own thread) instead of appending to this thread...... How do I start a new thread?When you are logged on to these forums, there is a button made visible near the top of each forum that says "Start New Topic". This will allow you to weave your own topic within the fabric of that chosen forum. 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