jvanegmond Posted October 30, 2006 Posted October 30, 2006 (edited) I want the first two matches to be valid, the second two to be invalid, using StringRegExp. None of my patterns work as I expect them to: Dim $Password[4] = ["123","12345678","12","123456789"] For $x = 0 to UBound($Password)-1 If StringRegExp($Password[$x], "(\d){2,8}") == 1 Then MsgBox(0, "StringRegExp", $Password[$x] & " is a valid text") Else MsgBox(0, "StringRegExp", $Password[$x] & " is not valid") EndIf Next Dim $Password[4] = ["abc","abcdefgh","ab","abcdefghi"] For $x = 0 to UBound($Password)-1 If StringRegExp($Password[$x], "(\a){2,8}") == 1 Then MsgBox(0, "StringRegExp", $Password[$x] & " is a valid text") Else MsgBox(0, "StringRegExp", $Password[$x] & " is not valid") EndIf Next Dim $Password[4] = ["1bc","ab3de6gh","a2","a2cd5fgh9"] For $x = 0 to UBound($Password)-1 If StringRegExp($Password[$x], "(\a|\d){2,8}") == 1 Then MsgBox(0, "StringRegExp", $Password[$x] & " is a valid text") Else MsgBox(0, "StringRegExp", $Password[$x] & " is not valid") EndIf Next This is for a checker wether a users enters a valid password. (a-z A-Z 0-9 are allowed) Edited October 30, 2006 by Manadar github.com/jvanegmond
jvanegmond Posted October 30, 2006 Author Posted October 30, 2006 (edited) I want this stickied until I get a answer. What is the right pattern, to check if a string is between 3 and 8 characters long and only exists of characters a-z A-Z and 0-9? Edited October 30, 2006 by Manadar github.com/jvanegmond
Moderators SmOke_N Posted October 30, 2006 Moderators Posted October 30, 2006 (edited) See if you can figure the answer out from this example, I don't have time to work it out for you, but at least you will see what StringRegExp() is seeingDim $Password[4] = ["123","12345678","12","123456789"] For $x = 0 to UBound($Password)-1 $array = StringRegExp($Password[$x], "^(\d{2,8})$", 3) If IsArray($array) Then MsgBox(0, "StringRegExp", $Password[$x] & " is a valid text" & @CRLF & $array[0]) Else MsgBox(0, "StringRegExp", $Password[$x] & " is not valid") EndIf NextoÝ÷ ØGb´ú,µçp®à{¦¦Wv+vêÞßÛ-êÞ²Ú¶¦jëh×6Dim $Password[4] = ["abc","abcdefgh","ab","abcdefghi"] For $x = 0 to UBound($Password)-1 If StringRegExp($Password[$x], "^([a-zA-Z]{2,8})$") Then MsgBox(0, "StringRegExp", $Password[$x] & " is a valid text") Else MsgBox(0, "StringRegExp", $Password[$x] & " is not valid") EndIf Next Dim $Password[4] = ["1bc","ab3de6gh","a2","a2cd5fgh9"] For $x = 0 to UBound($Password)-1 If StringRegExp($Password[$x], "^([\w|\d]{2,8})$") Then MsgBox(0, "StringRegExp", $Password[$x] & " is a valid text") Else MsgBox(0, "StringRegExp", $Password[$x] & " is not valid") EndIf Next Edited October 30, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
jvanegmond Posted October 31, 2006 Author Posted October 31, 2006 (edited) The next script only flags the last one as a valid text. StringRegExp == StringInStr ? I don't think so.Dim $Password[4] = ["1bc","ab3de6gh","a2","a2cd5fgh9"] For $x = 0 to UBound($Password)-1 If StringRegExp($Password[$x], "5") Then MsgBox(0, "StringRegExp", $Password[$x] & " is a valid text") Else MsgBox(0, "StringRegExp", $Password[$x] & " is not valid") EndIf NextEdit: I also found no reference in the helpfile to using either ^ or $ inside the test pattern. I think ^ means not, as it is used inside a group once as a not operator. $ beats me. Edited October 31, 2006 by Manadar github.com/jvanegmond
Moderators SmOke_N Posted October 31, 2006 Moderators Posted October 31, 2006 (edited) The next script only flags the last one as a valid text. StringRegExp == StringInStr ? I don't think so. Dim $Password[4] = ["1bc","ab3de6gh","a2","a2cd5fgh9"] For $x = 0 to UBound($Password)-1 If StringRegExp($Password[$x], "5") Then MsgBox(0, "StringRegExp", $Password[$x] & " is a valid text") Else MsgBox(0, "StringRegExp", $Password[$x] & " is not valid") EndIf NextIs that your way of a thank you? Edit: I also found no reference in the helpfile to using either ^ or $ inside the test pattern. I think ^ means not, as it is used inside a group once as a not operator. $ beats me.Maybe do some homework if you really want to use something? http://perldoc.perl.org/perlre.html#Regular-Expressions Edit: Had a quote in the wrong spot. Edited October 31, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
jvanegmond Posted October 31, 2006 Author Posted October 31, 2006 Sorry, Smoke. I'm frustrated because I can't get this to work for me, and what the helpfile says and what StringRegExp does appears contradictory to me. I feel like I'll never get this. I also had no idea that StringRegExp used the same syntax as the perl version, so I didn't think it wasn't relevant to search for any perl syntax. Trying to get the right pattern to match characters and numbers seems so simple to me, but I feel like using StringInStr now. github.com/jvanegmond
jvanegmond Posted October 31, 2006 Author Posted October 31, 2006 (edited) Smoke_N, Thank you! I have implemented this and it's working.My sincere apologies for not recognizing the effort you had put into it the first time, I was very frustrated with the code in the first place.For anyone reading this at a later date, and is interested in the code, Here it is:Dim $Password[8] = ["1bc","ab3de6gh","a2","a2cd5fgh9","!@#$%", "^&*()_","mana dar","manadar"] For $x = 0 to UBound($Password)-1 If StringRegExp($Password[$x], "^([\w|\d]{3,8})$") Then MsgBox(0, "StringRegExp", $Password[$x] & " is a valid text") Else MsgBox(0, "StringRegExp", $Password[$x] & " is not valid") EndIf Next Edited October 31, 2006 by Manadar github.com/jvanegmond
Moderators SmOke_N Posted October 31, 2006 Moderators Posted October 31, 2006 Smoke_N, Thank you! I have implemented this and it's working. My sincere apologies for not recognizing the effort you had put into it the first time, I was very frustrated with the code in the first place. For anyone reading this at a later date, and is interested in the code, Here it is: Dim $Password[8] = ["1bc","ab3de6gh","a2","a2cd5fgh9","!@#$%", "^&*()_","mana dar","manadar"] For $x = 0 to UBound($Password)-1 If StringRegExp($Password[$x], "^([\w|\d]{3,8})$") Then MsgBox(0, "StringRegExp", $Password[$x] & " is a valid text") Else MsgBox(0, "StringRegExp", $Password[$x] & " is not valid") EndIf NextGood deal... Did you figure out you can use ^ to truncate as well as state it was at the beginning of the line? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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