Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在标记内部的标记上使用正则表达式?_C#_Regex - Fatal编程技术网

C# 如何在标记内部的标记上使用正则表达式?

C# 如何在标记内部的标记上使用正则表达式?,c#,regex,C#,Regex,我现在正在写一个小项目,它使用正则表达式来解析模板,现在最大的问题是我们在这里也有一个includes标签,这使得它有点困难 Regex reg = new Regex(@"##############TEMPLATEENGINE(^#)##############(.*?)##############TEMPLATEENGINE(\1)##############", RegexOptions.IgnoreCase | RegexOptions.Compiled); 适用于模板,如 TEMP

我现在正在写一个小项目,它使用正则表达式来解析模板,现在最大的问题是我们在这里也有一个includes标签,这使得它有点困难

Regex reg = new Regex(@"##############TEMPLATEENGINE(^#)##############(.*?)##############TEMPLATEENGINE(\1)##############", RegexOptions.IgnoreCase | RegexOptions.Compiled);
适用于模板,如

TEMPLATEENGINE$$startswith$$帐户:firstname$$Firstn 废话

TEMPLATEENGINE$$startswith$$帐户:firstname$$Firstn TEMPLATEENGINEaccount:firstname属性缺少:firstname!TEMPLATEENGINEaccount:firstname 但只要我有一个像这样的模板

TEMPLATEENGINE$$startswith$$帐户:firstname$$Firstn 废话

TEMPLATEENGINEaccount:firstname属性缺少:firstname!TEMPLATEENGINEaccount:firstname TEMPLATEENGINE$$startswith$$帐户:firstname$$Firstn 布拉赫


它只是找到了内部模板,尽管我认为\1应该确保开始和结束应该相等……

我尝试过让这个模式工作:

########TEMPLATEENGINE([^#]+)##############(((?!########TEMPLATEENGINE(?!\1)).)*)########TEMPLATEENGINE\1##############
但到目前为止运气不好,我需要继续前进——我已经发布了它,以防有所帮助,因为我认为这项技术是可靠的。我会删除它以后或修复它,如果我可以!如果没有人使用它,请不要投票否决它-我不是说它是一个完整的解决方案

注意,您需要迭代匹配表达式,首先捕获内部标记


另请注意,TEMPLATEENGINEaccount:firstname的结束标记的格式似乎与缺少后缀的示例不同-这是一个问题吗?

能否请您提供更清楚的详细信息?标记中的标记是什么意思?