Mastering GUIDs with Occam's Razor

Interesting that you’re only checking that your string LOOKS like a GUID, not that it actually IS one, but I’m just being pedantic (hint: UUIDs/GUIDs are versioned, with the latter being a subset of the former–not all UUIDs are GUIDs [as defined by Microsoft])

When push comes to shove, using exceptions to control program flow is quite evil. It’s basically a posh GOTO. The regex is effectively a hard coded literal, but it can be wrapped up in a constant somewhere.

using exceptions to control program flow is evil

So is not providing an equivalent TryParse method for every Parse method in the BCL.

I think most sane people would prefer the non-exception-catching dependent way. However, I would step into the guid constructor source to see what they are doing. Using a regex to match a guid pattern seems like enormous overkill.

Interestingly everyone has fallen into the trap of discussing this non-topic. Yes, the regex version is faster, and if you need to validate 100,000 guids in your normal program operation (as opposed to just a one off) then use the regex.

For every other scenario i’ll stick with the one which is easier to type and remember. Of course, if they stick a regex version into the TryParse function of the GUID object in .net 3.5 then i’ll happily use it every time.