Sign in to follow this  
Followers 0
Bokkie

Regular Expression Syntax.

11 posts in this topic

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. :)

Share this post


Link to post
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.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
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.


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

You require the latest BETA release.

#)

It's a bad day for me. Where do I find the beta download?

Edit: I found it...

Edited by Peter Hamilton-Scott

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