Jump to content

Regular Expression Syntax.


Recommended Posts

Can anyone help me with a regular expression that will validate the GUID below?

{1B399A41-C1D0-40A2-9E4F-095868EFAF01}

I'd like to be really strict and take the braces and dash characters into account as well as verify the hex groups are comprised of hex characters and don't contain non-hex characters like Z and T for example. I confess I'm hopeless with regular expressions so a free virtual crate of beers to the first contributor. :)

Link to comment
Share on other sites

Can anyone help me with a regular expression that will validate the GUID below?

{1B399A41-C1D0-40A2-9E4F-095868EFAF01}

I'd like to be really strict and take the braces and dash characters into account as well as verify the hex groups are comprised of hex characters and don't contain non-hex characters like Z and T for example. I confess I'm hopeless with regular expressions so a free virtual crate of beers to the first contributor. :)

i actually don't use regexp (i am too lazy to try to wrap my head around them) but i can write you up a real quick validator with string functions.
Link to comment
Share on other sites

I don't normally either, but I can figure out the helpfile well enough to produce this:

MsgBox (0, "", StringRegExp ("{1B399A41-C1D0-40A2-9E4F-095868EFAF01}", "(\x{8}\-\x{4}\-\x{4}\-\x{4}\-\x{12})"))

It returns 1, which means it passes.

Edited by greenmachine
Link to comment
Share on other sites

I don't normally either, but I can figure out the helpfile well enough to produce this:

MsgBox (0, "", StringRegExp ("{1B399A41-C1D0-40A2-9E4F-095868EFAF01}", "(\x{8}\-\x{4}\-\x{4}\-\x{4}\-\x{12})"))

It returns 1, which means it passes.

you think you're better than me?! :)

kidding. i won't do better than one line of code with what i'm working on, and it looks like problem is solved. good job man.

Link to comment
Share on other sites

I don't normally either, but I can figure out the helpfile well enough to produce this:

MsgBox (0, "", StringRegExp ("{1B399A41-C1D0-40A2-9E4F-095868EFAF01}", "(\x{8}\-\x{4}\-\x{4}\-\x{4}\-\x{12})"))

It returns 1, which means it passes.

Thanks, greenmachine

I know little now... :)

so much easier to understand with an example.

Edited by Joon
Link to comment
Share on other sites

you think you're better than me?! :)

kidding. i won't do better than one line of code with what i'm working on, and it looks like problem is solved. good job man.

Actually I was really surprised that it worked on my first try... most things don't work out that well.

Hmm, I just noticed that it doesn't check the brackets... and now that I test more I'm noticing that it doesn't actually return 0 for anything.... time to redo the pattern.

Edit - Fixed the pattern: "\{\x{8}-\x{4}-\x{4}-\x{4}-\x{12}\}"

Edited by greenmachine
Link to comment
Share on other sites

I wouldn't use regular expressions at all. Strip the {}- characters and then use StringIsXDigit() on it.

Func IsValidCLSID($sCLSID)
    Local $sTemp = StringReplace($sCLSID, "{", "")
    $sTemp = StringReplace($sTemp, "}", "")
    $sTemp = StringReplace($sTemp, "-", "")
    Return StringIsXDigit($sTemp)
EndFunc

A regular expression would probably be faster, however.

Link to comment
Share on other sites

I don't normally either, but I can figure out the helpfile well enough to produce this:

MsgBox (0, "", StringRegExp ("{1B399A41-C1D0-40A2-9E4F-095868EFAF01}", "(\x{8}\-\x{4}\-\x{4}\-\x{4}\-\x{12})"))

It returns 1, which means it passes.

I've got the latest release installed but my helpfile has nothing in it for StringRegExp. In fact I can't even find it anywhere and SciTE throws a compilation error saying the function could not be found. I can't find it listed in any include files. I've got 3.1.1 installed. Edited by Peter Hamilton-Scott
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...