gcue Posted June 23, 2023 Share Posted June 23, 2023 hi world I am trying to validate user input as valid syntax proper syntax is <any number><single letter> single letter can only be d,w,m,q,y (for day, w, month, quarter, year) this is what i have so far but not quite working $user_input = "499d" ;valid $user_input = "499dd" ;not valid because syntax is only 1 letter $user_input = "499r" ;not valid because character is not d,w,m,q,y $user_input = "d334" ;not valid because syntax is number then letter $user_input = "xyz" ;not valid because syntax is number then letter $user_input = StringRegExp(StringStripWS($user_input, 8), "([0-9]*[d,w,m,q,y])", 3) would like to provide an error if the syntax is not valid thank you in advance!! Link to comment Share on other sites More sharing options...
Solution jchd Posted June 23, 2023 Solution Share Posted June 23, 2023 (edited) Try this: Local $a = ["456w", "465dd", "456", "y45", "dwm"] For $s In $a $valid = StringRegExp(StringStripWS($s, 8), "^\d+[dwmqy]$") ConsoleWrite($s & " is " & ($valid ? "" : "in") & "valid" & @LF) Next If you accept uppercase letters as well, use this pattern instead: "(?i)^[0-9]+[dwmqy]$" Edited June 23, 2023 by jchd Zedna 1 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...
gcue Posted June 23, 2023 Author Share Posted June 23, 2023 Thank you very much! Works great Link to comment Share on other sites More sharing options...
gcue Posted June 26, 2023 Author Share Posted June 26, 2023 (edited) the syntax checking works great thanks again Jchd! however, i am unable to single out each min/max volume when im trying to read input from a text file. was working but noticing its not consistently working. sample input - each value is in its own line (could be with or without spaces min: 5d or min:5d😞 min: 5m max: 34d this is what i am doing to get each of the values but not consistently working: $min_value = StringRegExp(StringStripWS($expecting, 8), "\min:([0-9a-z]*[^max:])", 3) $max_value = StringRegExp(StringStripWS($expecting, 8), "\max:([0-9a-z]*)", 3) what i am expecting is $min_value = 5d $max_value = 34m thank you again in advance! Edited June 26, 2023 by gcue Link to comment Share on other sites More sharing options...
Andreik Posted June 26, 2023 Share Posted June 26, 2023 I am not very sure about what are you asking but try this. $sData = 'min: 5d' & @CRLF $sData &= 'max: 34m' $Min = StringRegExp($sData, '(?i)min: *?(\d+[d,w,m,q,y])', 3) $Max = StringRegExp($sData, '(?i)max: *?(\d+[d,w,m,q,y])', 3) ConsoleWrite($Min[0] & @CRLF) ConsoleWrite($Max[0] & @CRLF) Zedna 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
gcue Posted June 26, 2023 Author Share Posted June 26, 2023 that is exactly what i was looking for! thank you VERY much!!! hope you have a great rest of the week! 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