2016-04-27 278 views
0

我試圖取代從這個字符串的GUID列表:正則表達式替換字符串

<Field Type=\"Lookup\" DisplayName=\"Human Resources Document Category\" Required=\"FALSE\" EnforceUniqueValues=\"FALSE\" List=\"{28365191-64ab-4b28-9ebe-427d66ed4e3a}\" WebId=\"a033826b-2bc7-4f95-8054-2fd4423c53d0\" ShowField=\"Title\" Mult=\"FALSE\" UnlimitedLengthInDocumentLibrary=\"FALSE\" Group=\"Custom Columns\" ID=\"{b87d7bc5-43da-490d-8303-ecbb0702bcd3}\" SourceID=\"{a033826b-2bc7-4f95-8054-2fd4423c53d0}\" StaticName=\"Human_x0020_Resources_x0020_Document_x0020_Category\" Name=\"Human_x0020_Resources_x0020_Document_x0020_Category\" Version=\"1\" />

所以我想改變列表=「{GUID}」來"{b87d7bc5-43da-490d-8303-ecbb0702bcd3}"

燦」 t似乎找到了這樣做的正則表達式。嘗試String.Replace,但似乎無法做到這一點。

感謝

+0

對不起,用新的GUID更新。 – user3519261

回答

0

請嘗試:

var input1 = "<Field Type=\"Lookup\" DisplayName=\"Human Resources Document Category\" Required=\"FALSE\" EnforceUniqueValues=\"FALSE\" List=\"{28365191-64ab-4b28-9ebe-427d66ed4e3a}\" WebId=\"a033826b-2bc7-4f95-8054-2fd4423c53d0\" ShowField=\"Title\" Mult=\"FALSE\" UnlimitedLengthInDocumentLibrary=\"FALSE\" Group=\"Custom Columns\" ID=\"{b87d7bc5-43da-490d-8303-ecbb0702bcd3}\" SourceID=\"{a033826b-2bc7-4f95-8054-2fd4423c53d0}\" StaticName=\"Human_x0020_Resources_x0020_Document_x0020_Category\" Name=\"Human_x0020_Resources_x0020_Document_x0020_Category\" Version=\"1\" />"; 
var pattern1 = "(?<=List=\\\").*?(?=\\\")"; 
var replace = "{b87d7bc5-43da-490d-8303-ecbb0702bcd3}"; 
var res = Regex.Replace(input1, pattern1, replace);