Jump to content

Regex question


rcmaehl
 Share

Recommended Posts

Currently I have

Switch StringLen($Serial)
        Case 0
            Return "Please Enter a Serial #"
        Case 1 To 6
            Return "UNKNOWN or INCORRECT"
        Case 7
            Select
                Case StringLeft($Serial, 2) = "79"
                    $Valid = "Device 1"
                Case StringLeft($Serial, 3) = "350"
                    $Valid = "Device 2"
                Case StringRegExp($Serial, "72[HR](.*)") ; Match 72H and 72R
                    $Valid = "Device 3"
                Case Else
                    $Valid = "UNKNOWN or INCORRECT"
            EndSelect
        Case 8
            Select
                Case StringRegExp($Serial, "\d[A-Z](.*)") ; Match a Digit (0-9), then a letter
                    $Valid = "Device 4 short format"
                Case Else
                    $Valid = "UNKNOWN or INCORRECT"
            EndSelect
    EndSwitch

Which I'm using to match a number followed by a letter then any number of digits up to a string length of 8 characters.

However I don't want it to match strings such as 1234A123 only 1D123456

Is there anyway to do this using a flag or am I limited to having to use StringLeft()?

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

1 hour ago, rcmaehl said:

Which I'm using to match a number followed by a letter then any number of digits up to a string length of 8 characters.

However I don't want it to match strings such as 1234A123 only 1D123456

Looks like a contradiction here: 1D123456 matches the first sentence. 1234A123 would also match if one interprets "a number" literally, whereas I believe you meant "a digit".

What about "^\d[A-Z]\d{0,6}" assuming "any number" really means what it says.

Edited by jchd

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

2 minutes ago, jchd said:

Looks like a contradiction here: 1D123456 matches the first sentence. 1234A123 would also match if one interprets "a number" literally, whereas I believe you meant "a digit".

What about "^\d[A-Z]\d{0,6}$" assuming "any number" really means what it says.

That works too, I was just hoping that there was a simple way to do "If Entire String Matches Regex Return True, Otherwise Return False"

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

I don't get it. The contradiction is still there.

You speak of case 8, correct?

Then what do you allow after the digit followed by the letter followed by any number of digits? Isn't that also contradictory with length = 8?

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

Found what I was looking for

StringRegExp($Serial, "\A\d[A-Z]\d{0,6}$")


Case 8 doesn't matter I just needed it to Return True if the above was met. I realize now that what I posted was confusing as I said any number of digits but the code contradicted me.

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

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

×
×
  • Create New...