我最近不得不在C#中翻譯propkeys.h(在C [++]?中)。正則表達式重複和捕獲
我的目標是來自:
DEFINE_PROPERTYKEY(PKEY_Audio_ChannelCount, 0x64440490, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 7);
要:
public static PropertyKey Audio_ChannelCount = new PropertyKey(new Guid("{64440490-4C8B-11D1-8B70-080036B11A03}"));
我用記事本+ +的正則表達式,但我接受任何其他腳本化解決方案(Perl中,sed的。 ..)。請不要編譯語言(如C#,Java ...)。
我結束了這個(工作):
// TURNS GUID into String
// Find what (Line breaks inserted for convenience):
0x([[:xdigit:]]{8}),\s*0x([[:xdigit:]]{4}),\s*0x([[:xdigit:]]
{4}),\s*0x([[:xdigit:]]{2}),\s*0x([[:xdigit:]]{2}),\s*0x([[:xdigit:]]
{2}),\s*0x([[:xdigit:]]{2}),\s*0x([[:xdigit:]]{2}),\s*0x([[:xdigit:]]
{2}),\s*0x([[:xdigit:]]{2}),\s*0x([[:xdigit:]]{2})
// Replace with:
new Guid\("{$1-$2-$3-$4$5-$6$7$8$9$10$11}"\)
// Final pass
// Find what:
^DEFINE_PROPERTYKEY\(PKEY_(\w+),\s*(new Guid\("\{[[:xdigit:]|\-]+"\)),\s*\d+\);$
// Replace with:
public static PropertyKey $1 = new PropertyKey\($2\);
雖然這是工作,我覺得第一遍一些奇怪的。我想用重複的替換{2}噸。 類似於:
(0x([[:xdigit:]]){2},\s*)+
但無法讓它與羣組一起工作。有人能告訴我用正則表達式來做這個「標準」方法嗎?