Terenz Posted November 27, 2013 Posted November 27, 2013 How i can know if a string has a predefinite "rule"? Example i have a string with 2 numbers, a slash, 3 numbers, a space, 2 letters, a slash, 3 letters So i'd like to know if a string follow this rule. Thanks Nothing is so strong as gentleness. Nothing is so gentle as real strength
Moderators Melba23 Posted November 27, 2013 Moderators Posted November 27, 2013 Terenz,You will need to use a "Reguar Expression" - the AutoIt function you need to use is StringRegExp. In this case you would need a pattern like: d{2}d{3}sw{2}w{3}And as it seems you have not had the pleasure of using these little buggers before, be prepared for your brain to begin bleeding as you get to grips with them. 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: Reveal hidden contents 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
Terenz Posted November 27, 2013 Author Posted November 27, 2013 Yes is my first time with regular expression, i'll check your example and the help for StringRegExp but seems a little complicated If i have some doubt i'll post here. Nothing is so strong as gentleness. Nothing is so gentle as real strength
jdelaney Posted November 27, 2013 Posted November 27, 2013 (edited) Use a regexp: $string1 = "11/123 aS/asa" ; will pass $string2 = "1a/123 as/asa" ; will not pass $regexp = "\d{2,2}/\d{3,3}\s[A-z]{2,2}/[A-z]{3,3}" $return1 = CheckStringFormat($string1, $regexp) $return2 = CheckStringFormat($string2, $regexp) ConsoleWrite($return1 & @CRLF) ConsoleWrite($return2 & @CRLF) Exit Func CheckStringFormat($sString,$sRegExp) Local $bReturn = False If StringRegExp($sString,$sRegExp,0) Then $bReturn = True Return $bReturn EndFunc Edited November 27, 2013 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.
Terenz Posted November 27, 2013 Author Posted November 27, 2013 Well i have a question Melba has write d{2}, does it mean 2 digit jdelaney has write d{2,2}, why there is a difference? I don't understand it Nothing is so strong as gentleness. Nothing is so gentle as real strength
jdelaney Posted November 27, 2013 Posted November 27, 2013 (edited) Try it out, there is no diference. One states the min, and max count (since they are the same number, it's redundant), the other shows the expected count. Don't use the w, though. That will return alpha and num chars (also _ ). [A-z] will return only alpha chars. Edited November 27, 2013 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.
Moderators Melba23 Posted November 27, 2013 Moderators Posted November 27, 2013 Terenz,My version is shorthand for jdelaney's - both say "exactly that number". I always point people to this site to begin to learn about RegExes. I am afraid they are far too big a subject to cover in a thread like this, even if I felt remotely qualified to do so. 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: Reveal hidden contents 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
Terenz Posted November 27, 2013 Author Posted November 27, 2013 I know both work but i have just try to understand why use two different method ( {2} and {2,2} ) for the same numeric string, there are different approach and i think this is not good for a regex noob like me Yes [A-z] fit well my string Nothing is so strong as gentleness. Nothing is so gentle as real strength
corgano Posted November 27, 2013 Posted November 27, 2013 (edited) http://gskinner.com/RegExr/ I've blabbed about it before, probably will again. this site is AMAZING for regular expression testing and creation. You can mouseover symbols at the top and it will tell you what they mean, it will show you groups, what it matches, what it returns. It even has a list of bits and peices in the right hand side that;s amazingly useful. RegExp is standardizes so you can copy paste that into autoit's stringregexp() function. Tips: mode 3 for stringregexp() will return all the results as an array, and adding (?i) in front of the pattern makes it case insensitive. Happy Regexing Edit: I also recently learned that when you have a set, say d, you can follow it by {2,6} to match between 2 and 6 times Edited November 27, 2013 by corgano 0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e
jchd Posted November 27, 2013 Posted November 27, 2013 corgano, The site you recommend may be pretty but it doesn't implement the same regular expression flavor as AutoIt uses (namely: PCRE). Reveal hidden contents 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)
mikell Posted November 27, 2013 Posted November 27, 2013 (edited) $regexp = '\d\d/\d{3}\h[[:alpha:]]{2}/[[:alpha:]]{3}' h instead of s because a vertical space in the string will not provide an expected match - probably Edited November 27, 2013 by mikell
corgano Posted November 27, 2013 Posted November 27, 2013 On 11/27/2013 at 8:39 PM, jchd said: corgano, The site you recommend may be pretty but it doesn't implement the same regular expression flavor as AutoIt uses (namely: PCRE). Can you give me an example? Everything I have had in there works in autoit, with the exception of the in-string flags which are different 0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e
jchd Posted November 28, 2013 Posted November 28, 2013 More precisely, actionscript uses ECMA specifications but AutoIt uses the PCRE engine. Hex input syntax differ. ECMA doesn't support Unicode character properties (AutoIt beta and next release will), subroutines, conditionals, recursion, ... There are too many important differences to list exhaustively. So yes this tool will deliver the same results as AutoIt for the simplest patterns but will turn in turmoil for general use. Reveal hidden contents 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)
corgano Posted November 28, 2013 Posted November 28, 2013 (edited) Thanks for the info! It's been good enough for me so far, I thought other people might find it useful when they start out with regexp. I like how simple it is. So ECMA is older / less advanced than PCRE? that would mean things in regexr will work in autoit but autoit patterns might not work in regexr right? Do you know of a similar tool that supports all of the PCRE regex features? I found this one but It's a bit more complicated to use. Nice diagrams though Edited November 28, 2013 by corgano 0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e
jchd Posted November 28, 2013 Posted November 28, 2013 ECMA and PCRE are simply not fully compatible. There are some available on this forum and a good link in my signature (pcretest for instance). Reveal hidden contents 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)
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