积极答复者
怎么使用正则把由特定前缀字符串和特定后缀字符串以及包含的内容一起提取出来?

问题
答案
-
Hi Trian555,
你可以用下面的代码去获得你想要的字符串。
string pattern = @"#{{[\s\S]*?}}#"; string s = "111#{{test1\ntest1}}#1111"; foreach (Match match in Regex.Matches(s, pattern)) { Console.WriteLine(match.Value); }
Result:
Best Regards,
Jack
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 Trian555 2019年8月2日 6:37
全部回复
-
Hi Trian555,
你可以用下面的代码去获得你想要的字符串。
string pattern = @"#{{[\s\S]*?}}#"; string s = "111#{{test1\ntest1}}#1111"; foreach (Match match in Regex.Matches(s, pattern)) { Console.WriteLine(match.Value); }
Result:
Best Regards,
Jack
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 Trian555 2019年8月2日 6:37