Sfikes Posted October 6, 2016 Posted October 6, 2016 $time = "23:20:23" $hey = StringRegExp($time, '(\w:\w:\w)') If $hey == 1 Then Send("Yes") EndIf If $hey == 0 Then Send("No") EndIf So i wanna know if my string has any numbers. To do that i used StringRegExp in order to check if the string was containing any numbers. So simply i want it to read like this: Any:Any:Any including the ":" but it always returns 0 as a "no match" which must mean that this script doesnt work. Any suggestions?
Moderators Melba23 Posted October 6, 2016 Moderators Posted October 6, 2016 Sfikes, Try this: #include <MsgBoxConstants.au3> $time = "23:20:23" $hey = StringRegExp($time, '(\d+:\d+:\d+)') If $hey = 1 Then MsgBox($MB_SYSTEMMODAL, "Result", "Yes") Else MsgBox($MB_SYSTEMMODAL, "Result", "No") EndIf The difference is that I am looking for at least one digit in section - you were looking for only a single digit, letter or underscore. 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
Sfikes Posted October 6, 2016 Author Posted October 6, 2016 2 minutes ago, Melba23 said: $hey = StringRegExp($time, '(\d+:\d+:\d+)') Thanks alot man! Works like a charm! Could you explain for me what \d+: means? I really wanna learn it.
Moderators Melba23 Posted October 6, 2016 Moderators Posted October 6, 2016 Sfikes, Reading the Help file page for StringRegExp will explain most of the possible parameters. In this case I used: Quote \d - Matches any decimal digit in conjunction with: Quote + - 1 or more So it will match if we have 3 groups of one or more digits separated by colons. To be really precise, we should really ask for groups of one or two digits which comes out as: $hey = StringRegExp($time, '(\d{1,2}:\d{1,2}:\d{1,2})') Try it with various strings and see how it performs. RegExes are quite tricky to learn (my brain still bleeds when developing a complex pattern) but are well worth the effort - I always recommend this site as a good place to start. 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
AutoBert Posted October 6, 2016 Posted October 6, 2016 31 minutes ago, Melba23 said: Sfikes, Try this: #include <MsgBoxConstants.au3> $time = "23:20:23" $hey = StringRegExp($time, '(\d+:\d+:\d+)') If $hey = 1 Then MsgBox($MB_SYSTEMMODAL, "Result", "Yes") Else MsgBox($MB_SYSTEMMODAL, "Result", "No") EndIf The difference is that I am looking for at least one digit in section - you were looking for only a single digit, letter or underscore. M23 I never understood (or invested not enough time) StringRegExp. I just tested your eample with a fantasy time: $time = "239:204:23" and i got also yes.
Moderators Melba23 Posted October 6, 2016 Moderators Posted October 6, 2016 Sfikes, Delighted I could help. 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
Surf243 Posted October 6, 2016 Posted October 6, 2016 In the future, these sites may help you with RegEx as they certainly helped me http://regexr.com/ - A playground for making RegEx https://regex101.com/- Another playground for making RegEx https://txt2re.com/ - Visually see and extract the data you want http://regex.inginf.units.it/ - Builds a RegEx based on examples you provide https://regexone.com/ - Learn RegEx Note: These sites are not made for specifically for AutoIt coding, but it's much easier than hitting F5 a dozen times to get what you want.
Moderators Melba23 Posted October 6, 2016 Moderators Posted October 6, 2016 (edited) AutoBert, Look at the other pattern I posted - that is more precise and only accepts one or two digits per group. M23 Edited October 6, 2016 by Melba23 Typo 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
jchd Posted October 6, 2016 Posted October 6, 2016 Just a note about the good links provided above: favor regex101.com as it offers the same regexp flavor as Autoit (PCRE). The reference documentation for PCRE implemented in AutoIt is http://www.pcre.org/original/doc/html/ (AutoIt doesn't implement PCRE2, yet). 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)
iamtheky Posted October 6, 2016 Posted October 6, 2016 1 hour ago, Sfikes said: So i wanna know if my string has any numbers. $time = "23:20:23" ;~ $time = "ElevenTwenty" msgbox(0, '' , AscW(stringleft($time , 1)) > 47 AND AscW(stringleft($time , 1)) < 58 ? "Yup" : "Nope") ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
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