473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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.IsMatch(__systemGUID,
@"^([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})"))

Thanks.
Nov 16 '05 #1
4 5950
"Greg Merideth" <be*****@forwardtechnology.net> wrote in message
news:j8********************@comcast.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.IsMatch(__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***********************@hotmail.com
Above views may belong only to me.
Nov 16 '05 #2
Greg Merideth <be*****@forwardtechnology.net> wrote in
news:j8********************@comcast.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.IsMatch(__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*****@forwardtechnology.net> wrote in
news:j8********************@comcast.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.IsMatch(__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 #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*****@forwardtechnology.net> wrote in
news:j8********************@comcast.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.IsMatch(__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
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....
4
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...
2
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...
20
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...
17
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 ...
4
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? ...
5
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...
4
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...
11
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.