473,804 Members | 3,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regex guid tester

I came up with this to test strings passed into a checking method to see
if the guid being passed in (regular 128 bit windows registry GUID) is
valid.

So far it seems to handle most errors thrown at it but today during a
test, a bracket "}" passed through the method as a valid guid so I
wanted to know if this expresion will stop invalid guids or did I miss
something?

__systemGUID is the string passed in.

if(!Regex.IsMat ch(__systemGUID ,
@"^([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})"))

Thanks.
Nov 16 '05 #1
4 5977
"Greg Merideth" <be*****@forwar dtechnology.net > wrote in message
news:j8******** ************@co mcast.com...
I came up with this to test strings passed into a checking method to see if the guid being passed in (regular 128 bit windows
registry GUID) is valid.

So far it seems to handle most errors thrown at it but today during a test, a bracket "}" passed through the method as a valid
guid so I wanted to know if this expresion will stop invalid guids or did I miss something?

__systemGUID is the string passed in.

if(!Regex.IsMat ch(__systemGUID , @"^([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})"))
The non-dash stuff should be hexadecimal, not any old
alphanumeric character.
Thanks.


--
--Larry Brasfield
email: do************* **********@hotm ail.com
Above views may belong only to me.
Nov 16 '05 #2
Greg Merideth <be*****@forwar dtechnology.net > wrote in
news:j8******** ************@co mcast.com:
I came up with this to test strings passed into a checking
method to see if the guid being passed in (regular 128 bit
windows registry GUID) is valid.

So far it seems to handle most errors thrown at it but today
during a test, a bracket "}" passed through the method as a
valid guid so I wanted to know if this expresion will stop
invalid guids or did I miss something?

__systemGUID is the string passed in.

if(!Regex.IsMat ch(__systemGUID ,
@"^([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})"))

Thanks.


Greg,

To expand on Larry's answer, \w matches way too many different
characters. Your regex matches strings like this:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Instead of \w, a character class of [\dA-Fa-f] should be used:

^([\dA-Fa-f]{8}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{12})

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #3
The following also takes into account curly braces in a guid, and it
contains a end of line marker ($).

^\{?[\dA-Fa-f]{8}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{12}\}?$

Without the end-of line, the following would slip through:
CEEBB5B7-5AB7-4605-B5B3-39D8A9511517NOT _VALID!!!!

Regards,
Joakim

Chris R. Timmons wrote:
Greg Merideth <be*****@forwar dtechnology.net > wrote in
news:j8******** ************@co mcast.com:

I came up with this to test strings passed into a checking
method to see if the guid being passed in (regular 128 bit
windows registry GUID) is valid.

So far it seems to handle most errors thrown at it but today
during a test, a bracket "}" passed through the method as a
valid guid so I wanted to know if this expresion will stop
invalid guids or did I miss something?

__systemGUI D is the string passed in.

if(!Regex.IsM atch(__systemGU ID,
@"^([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})"))

Thanks.

Greg,

To expand on Larry's answer, \w matches way too many different
characters. Your regex matches strings like this:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Instead of \w, a character class of [\dA-Fa-f] should be used:

^([\dA-Fa-f]{8}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{12})

Nov 16 '05 #4
Ahh that damm "$" is what I forgot to add to the regex check. Must be
old age.

Thanks.

Joakim Karlsson wrote:
The following also takes into account curly braces in a guid, and it
contains a end of line marker ($).

^\{?[\dA-Fa-f]{8}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{12}\}?$
Without the end-of line, the following would slip through:
CEEBB5B7-5AB7-4605-B5B3-39D8A9511517NOT _VALID!!!!

Regards,
Joakim

Chris R. Timmons wrote:
Greg Merideth <be*****@forwar dtechnology.net > wrote in
news:j8******** ************@co mcast.com:
I came up with this to test strings passed into a checking
method to see if the guid being passed in (regular 128 bit
windows registry GUID) is valid.

So far it seems to handle most errors thrown at it but today
during a test, a bracket "}" passed through the method as a
valid guid so I wanted to know if this expresion will stop
invalid guids or did I miss something?

__systemGUID is the string passed in.

if(!Regex.IsMat ch(__systemGUID ,
@"^([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})"))

Thanks.


Greg,

To expand on Larry's answer, \w matches way too many different
characters. Your regex matches strings like this:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Instead of \w, a character class of [\dA-Fa-f] should be used:

^([\dA-Fa-f]{8}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{4}-[\dA-Fa-f]{12})

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2418
by: Alan Pretre | last post by:
Can anyone help me figure out a regex pattern for the following input example: xxx:a=b,c=d,yyy:e=f,zzz:www:g=h,i=j,l=m I would want four matches from this: 1. xxx a=b,c=d 2. yyy e=f 3. zzz (empty) 4. www g=h,i=j,l=m
4
4382
by: Demetri | last post by:
Lets pretend you have a string array and each element is a sentence. Two of those elements read as follows: 1. The fox escaped from the hound. 2. The fox almost escaped. Now lets say you loop the string array and inside that loop you use a Regex class to determine if the current element matches a certain criteria. The criteria being as follows:
2
2001
by: John Baro | last post by:
I need to determine when multiple fonts are selected in a richtextbox. A font is indicated by \fcharset(N) where (N) is a number. (To the best of my knowledge) I can use this statement int Matches = 0; for(Match m = Regex.Match(rtfTextEdit.SelectedRtf, @"\\fcharset\d"); m.Success; m = m.NextMatch()) {
20
8122
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex matches are called within a loop (like if or for). E.g. for(int i = 0; i < 10; i++) { Regex r = new Regex();
17
3983
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher http://forta.com/books/0672325667/
4
1308
by: Krakatioison | last post by:
My problem is simple, but I spent lot of time playing with regex and I am going nuts. I need to automatically (many times per day) extract HEADING and DESCRIPTION from the html code below? HTML CODE: <a href="http://www.mylink.com">HEADING</a><br>DESCRIPTION<br>
5
6345
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of uniqueidentifier, originally taken from objectGUID from active directory domain)
4
1619
by: atrus123 | last post by:
Hi all, I'm trying to take a line like this: <guid isPermaLink="false">Entry 29</guid> Strip it of everything but the number, push that number into an array of other numbers, add one to the highest value, and print that value. if ($ngrab =~ /<guid.*/) { $ngrab =~ s/<guid.*Entry.//i; $ngrab =~ s/<\/guid>//i; push(@guid, $ngrab);
11
4945
by: coflo | last post by:
Hello I would like to replace an a href link that is provided in the RSS below with my own link. The link that I am looking to replace is defined in the <description> tag within the RSS. Im guessing I need to use some sort of function in combination with regex. I am able to create a regex to find and replace the a href link very easily; however, using regex in combination with a find and replace in XSL i am extremly novice. I am wanting...
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.