[英]RegEx to parse custom tags
I would like to parse following input. 我想解析以下输入。
{*HEADER}
Product
{*DESCRIPTION}
Product Name
{*HEADER}
Service
{*DESCRIPTION}
Service Name
and the output should be something like . 和输出应该是这样的。
List<Dictionary <string,string> >
key = HEADER , value = Product
Key = DESCRIPTION , value = Product Name
and same for the next object of list. 和列表的下一个对象相同。
My idea of parsing your input would be the use of negated class and capturing groups . 我解析输入的想法是使用否定类和捕获组 。
{\*([^}]+)}\s*([^{]*[^\s{])
[{\\*([^}]+)}
will capture the key to $1
[{\\*([^}]+)}
将捕获$1
的密钥 \\s*
followed by any amount of whitespace \\s*
后跟任意数量的空格 ([^{]*[^\\s{])
captures the value to $2
not ending in a whitespace (right trimmed). ([^{]*[^\\s{])
将值捕获为$2
而不以空格结尾(右修剪)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.