【发布时间】:2011-04-21 16:12:49
【问题描述】:
我正在解析一些用冒号分隔的键值对。我遇到的问题是,在值部分有我想忽略的冒号,但 split 函数无论如何都会捡起它们。
样本:
Name: my name
description: this string is not escaped: i hate these colons
date: a date
在单独的行上,我尝试了这个line.split(/:/, 1),但它只匹配数据的值部分。接下来我尝试了line.split(/:/, 2),但这给了我['description', 'this string is not escaped'],我需要整个字符串。
感谢您的帮助!
【问题讨论】:
标签: javascript regex split