问题描述
我正在使用正则表达式在文本块中搜索 UUID.目前我依赖的假设是所有 UUID 都将遵循 8-4-4-4-12 十六进制数字的模式.
I'm searching for UUIDs in blocks of text using a regex. Currently I'm relying on the assumption that all UUIDs will follow a patttern of 8-4-4-4-12 hexadecimal digits.
谁能想到一个用例,这个假设是无效的,会导致我错过一些 UUID?
Can anyone think of a use case where this assumption would be invalid and would cause me to miss some UUIDs?
推荐答案
我同意根据定义您的正则表达式不会遗漏任何 UUID.但是,请注意,如果您专门搜索 Microsoft 的全球唯一标识符 (GUID),则 GUID 有五种等效的字符串表示形式:
I agree that by definition your regex does not miss any UUID. However it may be useful to note that if you are searching especially for Microsoft's Globally Unique Identifiers (GUIDs), there are five equivalent string representations for a GUID:
"ca761232ed4211cebacd00aa0057b223"
"CA761232-ED42-11CE-BACD-00AA0057B223"
"{CA761232-ED42-11CE-BACD-00AA0057B223}"
"(CA761232-ED42-11CE-BACD-00AA0057B223)"
"{0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}"
这篇关于使用正则表达式在文本中搜索 UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!