如何转换
"one,cubic-bezier(0, 0, 1, 1), cubic-bezier(0, 0, 1, 1), linear"
至
["one", "cubic-bezier(0, 0, 1, 1)", "cubic-bezier(0, 0, 1, 1)", "linear"]
如何?
JavaScript。
这不一样。因为引号(左侧和右侧),这里( - 左,) - 右。
不要在 JS 中工作。
'ease,cubic-bezier(0, 0, 1, 1), linear,2,3'.split(/,(?=[^()]*((|$))/gi);
结果:
ease,(,cubic-bezier(0, 0, 1, 1),, linear,,2,,3
最佳答案
假设括号不能嵌套(在这种情况下,您将无法使用 JS 正则表达式风格)。
试试这个:
,(?![^()]*\))
快速分解:
, # match a comma [1]
(?! # start negative look ahead [2]
[^()]* # match zero or more non-parens chars [3]
\) # match the closing paren [4]
) # stop look ahead
用简单的英语来说,这将是:
match a comma [1], only if there's no closing paren [4] ahead [2] without the presence of any paren between the comma and the closing paren [3]
关于javascript - 正则表达式 : Split line by ",",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23293596/