正则表达式(提取键/值对) [英] Regular expression (extract key/value pairs)
本文介绍了正则表达式(提取键/值对)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从字符串中提取键/值对的列表(匹配).例如:
I'm trying to extract a list (match) of key/value pairs from a string. Ex :
PATH_1:"/", PATH_2:"/OtherPath", TODAY:"2016-06-27",XYZ :"1234"
这应该给出:
Key Value
PATH_1 /
PATH_2 /OtherPath
TODAY 2016-06-27
XYZ 1234
这是我正则表达式到目前为止的内容:
Here is what I have so far as regex :
((?:"[^"]*"|[^:,])*):((?:"[^"]*"|[^:,])*)
这很好用,除了当我添加一个带有'\'的路径时.例如:
This is well working except that when I'm adding a path having a '\'. Ex :
PATH_1:"c:\", PATH_2:"c:\OtherPath", TODAY:"2016-06-27"
当在双引号序列中找到时,我不知道如何指示正则表达式跳过分号.希望有人能帮助我.
I don't know how to instruct to regex expression to jump over semi-colon when found inside double quote sequence. Hope someone can help me.
PS:我正在使用QT.
PS : I'm using QT.
最诚挚的问候
推荐答案
https://regex101.com/r/vB1rS1/2
如果要删除引号,似乎只需从最后一个[]
中删除:
即可.
It seems that just removing the :
from the last []
may do it if the quotes are being removed.
((?:"[^"]*"|[^:,])*):((?:"[^"]*"|[^,])*)
这篇关于正则表达式(提取键/值对)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文