Jump to content

Filter for more than one value in a string!!


Fraser
 Share

Recommended Posts

Good evening,

To start, sorry if this has been posted/asked before have been searching for an answer for months now.

I have created a number/letter string generator for work (some call it a password generator but it’s much more than that :P ), currently I have a few IF statement that filter for bad letter formats i.e.

If StringRegExp($string, "c**k", 0) = 1 then

 generate()

ElseIf StringRegExp($string, "d**k", 0) = 1 then

 generate()

else

guictrlsetdata($label1, $string)

endif

My question is, is there any way to combine multiple search criteria in one IF statement?

Thank you.

Fraser

Edited by Fraser
Link to comment
Share on other sites

  • Moderators

Strictly in an If statement, you would have to use Or or And

If $x = 0 Or $x = 1 Then
    ;
EndIf
If $x = 0 And $y = 1 Then
    ;
EndIf

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I tried that one but unfortunately it doesn't work. :(

Tried this

ElseIf StringRegExp($Letters, '[a-z] | \d | [A-Z]', 0) = 1 Then

but this didn't work, so tried the below and it works a treat

ElseIf StringRegExp($Letters, '[a-z]', 0) = 1 And StringRegExp($Letters, "\d", 0) = 1 And StringRegExp($Letters, '[A-Z]', 0) = 1 Then

So look like I will have to stick with this, all though it means the statement is going to be massive!

Edited by Fraser
Link to comment
Share on other sites

  • Moderators

This may not be so in your case, just throwing out there that sometimes, depending on what you're searching for, it is easier to go with what is not than tons of Ifs.

If Not $x = 1 Then
   ExitLoop
Else
   ;Do stuff
EndIf

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I tried that one but unfortunately it doesn't work. :(

Tried this

ElseIf StringRegExp($Letters, '[a-z] | \d | [A-Z]', 0) = 1 Then

but this didn't work, so tried the below and it works a treat

ElseIf StringRegExp($Letters, '[a-z]', 0) = 1 And StringRegExp($Letters, "\d", 0) = 1 And StringRegExp($Letters, '[A-Z]', 0) = 1 Then

So look like I will have to stick with this, all though it means the statement is going to be massive!

If you really need to put spaces in the regular expression pattern that you do not want matched in the test string, you can add the option, "(?x)" to the RegExp pattern.  By default, whitespaces match themselves in RegExp patterns.

If StringRegExp("TestString", '(?x)[a-z] | \d | [A-Z]') Then ConsoleWrite("Passed" & @LF)
Link to comment
Share on other sites

Also, the all-in-one regexp requires the subject to contain a lowercase OR a digit OR an uppercase. The second version requires the subject to contain a lowercase AND a digit AND an uppercase

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 here
RegExp tutorial: enough to get started
PCRE 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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...