Sign in to follow this  
Followers 0
jvanegmond

StringRegExp... Again..

8 posts in this topic

#1 ·  Posted (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 by Manadar

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I want this stickied until I get a answer. :whistle: 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 by Manadar

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 seeing

Dim $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 by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

#4 ·  Posted (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
Next

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.

Edited by Manadar

Share this post


Link to post
Share on other sites

#5 ·  Posted (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
Next
Is 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 by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by Manadar

Share this post


Link to post
Share on other sites

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
Good deal...

Did you figure out you can use ^ to truncate as well as state it was at the beginning of the line?


[center]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.[/center]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0