The Darkside

Shedding light on things and stuff

 
  Home :: Contact :: Syndication  :: Login
  83 Posts :: 0 Stories :: 57 Comments :: 2 Trackbacks

Ads

 

Donate via PayPal...

...if you feel the site helped.

Archives

Post Categories

Open Source Projects

Other Blogs

Friday, September 03, 2010 #

I’ve been searching for a good regular expression to validate a string representation of a GUID, and even though there are 17 results on RegExLib.com and 73000+ on Google, I’ve not found one that matches the start and end braces correctly. Every single one I’ve found (without exaggerating, I read over 60 posts while looking)either matches a GUID without the braces, or those that match on a string including the braces allow for either only the first or last to be present.

^(?<-BRACE>\{)?[a-fA-F\d]{8}-(?:[a-fA-F\d]{4}-){3}[a-fA-F\d]{12}(?<-BRACE>\})?(?(BRACE)^.)$

On a side note: The project I’m doing maintenance on is VS2008/.Net 3.5. If you’re using .Net Framework 4, you can use the Guid.Parse and Guid.TryParse methods to validate a Guid.

UPDATE: I’ve submitted it to RegExLib.com.