MikeP Posted May 10, 2008 Share Posted May 10, 2008 (edited) Hi, I'm trying to validate an input box entry a bit like what you find on forum registration forms when your e-mail isn't typed correctly (syntax checker ? sorry...can't find the correct naming in english) Here's the type of string I want to validate : F2; F3; F10; F9; F3; F8 In other words, a list of function keys from F1 to F12 separated with "; " So far I'm stuck with this problem, the following string is validated because the pattern is found but I want to reject it because of the h $stringtest = "F4; F5; h" $pattern = "(F[123456789]; ){0,10}" ConsoleWrite(StringRegExp($stringtest , $pattern)&@CRLF) {0,10} is there to allow an empty string and maximum 10 keys When I'll solve this, I'll have the problem of finding how to add the F10 F11 and F12 since my pattern only check F1 to F9 I'm used to regexp but they're totally different in the other soft I'm using.. not Unix/Perl style, and writing regexps is a bit old for me.. *back to massive brain usage* Edited May 10, 2008 by MikeP Link to comment Share on other sites More sharing options...
martin Posted May 10, 2008 Share Posted May 10, 2008 (edited) Hi, I'm trying to validate an input box entry a bit like what you find on forum registration forms when your e-mail isn't typed correctly (syntax checker ? sorry...can't find the correct naming in english) Here's the type of string I want to validate : F2; F3; F10; F9; F3; F8 In other words, a list of function keys from F1 to F12 separated with "; " So far I'm stuck with this problem, the following string is validated because the pattern is found but I want to reject it because of the h $stringtest = "F4; F5; h" $pattern = "(F[123456789]; ){0,10}" ConsoleWrite(StringRegExp($stringtest , $pattern)&@CRLF) {0,10} is there to allow an empty string and maximum 10 keys When I'll solve this, I'll have the problem of finding how to add the F10 F11 and F12 since my pattern only check F1 to F9 I'm used to regexp but they're totally different in the other soft I'm using.. not Unix/Perl style, and writing regexps is a bit old for me.. *back to massive brain usage* I'm not so good on STRingRegExp. I would do it like this. $stringtest = "F4; F5; h" $pattern = StringSplit($stringtest,';') For $n = 1 To $pattern[0] $valid = True If StringRegExp($pattern[$n],"\h*F\d{1,2}\h*") = 0 then MsgBox(0,"ERROR",$pattern[$n]) EndIf Next EDIT:removed unnecessary quote characters (\Q \E) Edited May 10, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
MikeP Posted May 10, 2008 Author Share Posted May 10, 2008 (edited) My example was basic.. I'm trying to make a validation script that will reject this : F3;hF2; F9;k+]; fdjklm F3 with StringSplit you're assuming the string is correctly formed with "; " delimiters... (not ";" btw) further thinkings : if I can detect the biggest matching pattern in my string, that is, in : 'F4; F6; F9; F10; F10' get : 'F4; F6; F9; F10; F10' as result and not small patterns like 'F4; ' or 'F9; F10; F10;' then I can compare this result with the string.. if it's the same, my string is valid, if it's not that means the string has unnecessary characters like this : 'gfjdfdklj F4; F6; F9; F10; F10 djkj<>' ...the pattern exists but the string is not valid. Edited May 10, 2008 by MikeP Link to comment Share on other sites More sharing options...
martin Posted May 10, 2008 Share Posted May 10, 2008 My example was basic.. I'm trying to make a validation script that will reject this : F3;hF2; F9;k+]; fdjklm F3 with StringSplit you're assuming the string is correctly formed with "; " delimiters... (not ";" btw) further thinkings : if I can detect the biggest matching pattern in my string, that is, in : 'F4; F6; F9; F10; F10' get : 'F4; F6; F9; F10; F10' as result and not small patterns like 'F4; ' or 'F9; F10; F10;' then I can compare this result with the string.. if it's the same, my string is valid, if it's not that means the string has unnecessary characters like this : 'gfjdfdklj F4; F6; F9; F10; F10 djkj<>' ...the pattern exists but the string is not valid.Not sure I understand. Does this do what you want, even though it doesn't use StringRegExp? $stringtest = "F3;hF2; F9;k+]; fdjklm F3; F555" $pattern = StringSplit($stringtest, ';') For $n = 1 To $pattern[0] $valid = True $stemp = StringStripWS($pattern[$n], 3) If StringLen($stemp) > 3 Then $valid = False ElseIf StringMid($stemp, 1, 1) <> 'F' Then $valid = False Else $num = Number(StringMid($stemp, 2, StringLen($stemp) - 1)) If 'F' & $num <> $stemp Then $valid = False EndIf If Not $valid Then MsgBox(0, "Error", $stemp) Next Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
MikeP Posted May 10, 2008 Author Share Posted May 10, 2008 (edited) No it doesn't.. put a valid string in your test string and errors will popupwhat I need is to find the regexp way to say (in english language.. not using any regexp syntax here) :Find the largest substring in a string matching that statement :" F character immediately followed by one element in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) followed by ;[sPACE] " repeated 0 up to 10 timessaid another way, given $string = "blahblah F10; F3; F5; F5; F2; F9; F10; blahbahblah"return : expression found ! and $expression = "F10; F3; F5; F5; F2; F9; F10; "typically a situation to use regexps but until now I'm still searching how to write it Edited May 10, 2008 by MikeP Link to comment Share on other sites More sharing options...
MikeP Posted May 10, 2008 Author Share Posted May 10, 2008 Thanks Hubertus I was really stubborn about using Regexp (and I guess I will find how to write it in the long run) but your code is actually what I needed. I guess I'll use it and quit searching that regexp for a while.. got many other things to do and since I couldn't find a way to find a failure to your script .. all good ^^ ty again Link to comment Share on other sites More sharing options...
Greenhorn Posted May 10, 2008 Share Posted May 10, 2008 Hi, if you want to fish out the F2;F3;F5;F1;F8; ..., then try this: #include <Array.au3> $sString = 'blahblah F10; F3; F5; F5; F2; F9; F10; blahbahblah' $ptnExp = '(?-i:F\d*)' $aResult = StringRegExp($sString, $ptnExp, 3) ; will show F10, F3, F5, F5, F2, F9 and F10. _ArrayDisplay($aResult) Greetz Greenhorn Link to comment Share on other sites More sharing options...
Greenhorn Posted May 10, 2008 Share Posted May 10, 2008 #include <Array.au3> $sString = 'blahblah F10; F3; F5; F5; F2; F9; F10; blahbahblah' $ptnExp = '((?-i)(F\d?\d; )+)' $aResult = StringRegExp($sString, $ptnExp, 3) ; will show [0]|F10; F3; F5; F5; F2; F9; F10; ; and [1]|F10; ... _ArrayDisplay($aResult) Link to comment Share on other sites More sharing options...
MikeP Posted May 10, 2008 Author Share Posted May 10, 2008 (edited) Thanks both!Damn.. this : $ptnExp = '((?-i)(F\d?\d; )+)' is what I've been searching for roughly 3 hours... It does exactly what I wanted. Now let's take another hour to understand it.I realise I was having troubles too with StringRegexp since you're using Option 3 and I was struggling with 1 and 2...edit : nope.. still something missing since it will match this : "F24; F12; F3; F3; F99; "and I need to the first number to be only 1 .. or nothing (function keys.. F1 to F12 ) and if that character is set to 1.. then the 2nd character must belong to (0,1,2) to take only 10 11 and 12then.. this : $ptnExp = '((?-i)(F1?\d; )+)' will not match "F24; F12; F3; F99"the problem is it matches : "F13; F15; F18"I guess I will need conditional subpatterns or maybe assertions and I hope Autoit supports them...or I'll just keep going on with Hubertus's solution but we're so close to that regexp... Edited May 10, 2008 by MikeP Link to comment Share on other sites More sharing options...
aec Posted May 10, 2008 Share Posted May 10, 2008 @MikeP Propably the following pattern is also good for your purpose $pattern = "\A((?:F\d?\d; ){0,10})\Z" Link to comment Share on other sites More sharing options...
Greenhorn Posted May 10, 2008 Share Posted May 10, 2008 try this ... $ptnExp = '((F11?2?; ?)|(F\d; ?))' but I don't know how to get it in one row ... Greetz Greenhorn Link to comment Share on other sites More sharing options...
MikeP Posted May 10, 2008 Author Share Posted May 10, 2008 (edited) Nevermind !!! I, MikeP, apologizes to all Regexp purists... but I wrote it ... like this (lol) : $ptnExp = '((?-i)(F(1|2|3|4|5|6|7|8|9|10|11|12); )+)' ...sorry ..I'm out ! (and yes it works even if it's awful ahhaha) thx Greenhorn Edited May 10, 2008 by MikeP 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