[英]Regular Expression for tokenizing the list of Key=Value pair seperated by comma(,), where Value itself may contain a comma(,) in it
I have a requirement where I need to tokenise the list of key=value pairs separated by comma. 我有一个需要标记用逗号分隔的键=值对的列表的要求。 Ex:
$val1=abc, $val2=cde, $val3=efg
例如:
$val1=abc, $val2=cde, $val3=efg
Expected Output: 6 tokens 预期输出:6个令牌
I am using the regex ([^\\" =,]*(\\"[^\\"]*\\")[^\\" =,]*)|[^\\" =,]+
which solves the above problem. 我正在使用正则表达式
([^\\" =,]*(\\"[^\\"]*\\")[^\\" =,]*)|[^\\" =,]+
解决了上述问题。 But it is not handling the case when the value of key= value pair has a comma in it. 但它不处理的情况下,当键= 值对的值中有一个逗号。
Ex: $val1=abc,AB, $val2=cde, $val3=efg
例如:
$val1=abc,AB, $val2=cde, $val3=efg
Expected Output: 6 tokens 预期输出:6个令牌
But with the above regex am getting the output as shown below: Output: 7 tokens 但是使用上述正则表达式时,输出如下所示:输出:7个令牌
Can someone provide a proper regular expression which fits for the above case. 有人可以提供适合上述情况的正确正则表达式吗?
[^= ]+(?! \$)
Reads any amount of characters, that are not =
or space and are not followed by a space and $
. 读取任意数量的字符,这些字符不是
=
或空格,并且后面没有空格和$
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.