Steveiwonder Posted February 2, 2010 Share Posted February 2, 2010 (edited) Hey all,Didn't want to ask for someone to just do what i needed but can someone atleast confirm if i'm right/wrong. I'd like to point out RegExp's blow my brain!Firstly "$id" must be a combination of exactly 10 random numbers. Would the below work? (Yes i know how simple it is for you guru's, i just simply fail at Regular Expressions)$id = "2003714598" If StringRegExp($id, '\b[0-9]{10}\b') Then MsgBox(0, "Match", $id & " Found") Else MsgBox(0, "No Match", $id & " Not Found") EndIfAnd also this one..Has to match the start of the URL and then 7 random digits then the end of the URL.$url = "https://somerandomwebsite.ams.uk.com/details.php?i=1245795&t=d" If StringRegExp($url,"[https://somerandomwebsite.ams.uk.com/details.php?i=][0-9]{7}[&t=d]") Then MsgBox(0, "Match", $url & " Found") Else MsgBox(0, "No Match", $url & " Not Found") EndIfI would just like to know weather i have mastered (as far as my brain will allow) the art of Regular Expressions or can it be done another way.ThanksSteve Edited February 2, 2010 by Steveiwonder They call me MrRegExpMan Link to comment Share on other sites More sharing options...
Bowmore Posted February 2, 2010 Share Posted February 2, 2010 (edited) Your first RegEx pattern appears to be correct if you want to match a word that consists of exactly 10 numbers. There is an error with your second RegEx pattern. You should remove the [] from around the first part of the URL. As it is it will only match one of the characters between the square brackets and I assume that you want to match the whole of the first part of the URL. Also the last bit should not be enclosed by [] Edited February 2, 2010 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
jchd Posted February 2, 2010 Share Posted February 2, 2010 (edited) Let me expand a bit on the good answer already provided.You may also use \d in place of [0-9] to match a (decimal) digit. So your first reg. expression can be '\b\d{10}\b' equivalently. This is only a handy shorthand.\b matches a "word boundary" so the regexp above means "I match if I find a sequence of 10 decimal digits surrounded by whitespaces or begin/end of string"Hence '\b\d{10}\b' will hapily match 'gfhuo nio rzjlik hre 0123456789 blbdn lk'But If you want to enforce the rule that your input "must be a combination of exactly 10 random numbers" then the first regexp isn't exactly what you need, as the example above shows.Make your regexp '\A\d{10}\z', meaning "I match if the string contains exclusively a sequence of 10 decimal digits." This one leaves no room for chance.You see on this simple example that you can and probably should match precisely what you intent, nothing less but nothing more.For instance, what would you choose: "I say that the code is 0123456789 ... OMG, I made a horrible mistake: the actual code is 9876543210 forgive me dear fellow!"The first regexp will happily pick 0123456789 but the second one will bark, giving you the opportunity to catch the error.In short: regexp are very powerful and offer means to express precise conditions. When you use them routinely choose the right balance between being pointlessly too strict and lazily too permissive. Anyway, regexp will bring you joy and frustration, just like a real-life partner.EDIT: a couple of typos, my bad.[really bad, yet another: [0-9] = \d not \b of course. Thanks Trancexx!] Edited February 3, 2010 by jchd 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...
Steveiwonder Posted February 3, 2010 Author Share Posted February 3, 2010 I think i may be confusing myself... Without the [] it doesnt find match, but with it does. Local $oLinks[6] $oLinks[0] = "wadad" $oLinks[1] = "awdawd" $oLinks[2] = "354345$%@$%$:%@£$5" $oLinks[3] = "fewdawda.com wdwad23423 " $oLinks[4] = "https://randomsite.com/roooar/details.php?i=7548924&t=d" $oLinks[5] = "wddadd33444444322&&*&*£$%£" $pattern = "https://randomsite.com/roooar/details.php?i=[0-9]+&t=d" ;$pattern = "[https://randomsite.com/roooar/details.php?i=][0-9]+[&t=d]" For $oLink in $oLinks If StringRegExp($oLink, $pattern) then ;_IENavigate($oIE, $oLink) Msgbox(0,"Match", "Match Found") ExitLoop EndIf Next Thanks for both replies. Steve They call me MrRegExpMan Link to comment Share on other sites More sharing options...
Steveiwonder Posted February 3, 2010 Author Share Posted February 3, 2010 (edited) I think i may be confusing myself... Without the [] it doesnt find match, but with it does. Local $oLinks[6] $oLinks[0] = "wadad" $oLinks[1] = "awdawd" $oLinks[2] = "354345$%@$%$:%@£$5" $oLinks[3] = "fewdawda.com wdwad23423 " $oLinks[4] = "https://randomsite.com/roooar/details.php?i=7548924&t=d" $oLinks[5] = "wddadd33444444322&&*&*£$%£" $pattern = "https://randomsite.com/roooar/details.php?i=[0-9]+&t=d" ;$pattern = "[https://randomsite.com/roooar/details.php?i=][0-9]+[&t=d]" For $oLink in $oLinks If StringRegExp($oLink, $pattern) then ;_IENavigate($oIE, $oLink) Msgbox(0,"Match", "Match Found") ExitLoop EndIf Next Thanks for both replies. Steve I worked out what im doing wrong i think... I needed to escape some special characters? So the pattern i now have is this.. $pattern = "https\://randomsite\.com/roooar/details\.php\?i=[0-9]+&t=d" Am i on the right track? Edited February 3, 2010 by Steveiwonder They call me MrRegExpMan Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2010 Moderators Share Posted February 3, 2010 Steveiwonder, You have it. 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...
Steveiwonder Posted February 3, 2010 Author Share Posted February 3, 2010 (edited) Woop! Now anyone who needs help with RegExp's just throw them my way i have mastered the art! On a serious note, thanks everyone Edited February 3, 2010 by Steveiwonder They call me MrRegExpMan Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2010 Moderators Share Posted February 3, 2010 Steveiwonder,Woop! Now anyone who needs help with RegExp's just throw them my way i have mastered the art! Dream on........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...
trancexx Posted February 3, 2010 Share Posted February 3, 2010 ...EDIT: a couple of typos, my bad.You changed a but you forgot to change b.Nice post, btw. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
jchd Posted February 3, 2010 Share Posted February 3, 2010 You changed a but you forgot to change b. Oops, Good catch. That's age + no sleep. It was a good opportunity to have the OP's -and possibly some readers'- curiosity stimulated so that they dig further into regexp. In a while, OP and other will routinely write working "serious" regexps, just like this one, which will match any form of valid email address: This is page 316 of Jefferey' book Mastering Regular Expressions ed.1 (I didn't find it in text form on the Internet) 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