javascript - 正则表达式 : Split line by ","

标签 javascript regex regular-language

如何转换

"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/

相关文章:

php - mysql regex - 过滤后跟特定字符串的大于 XX 的数字

javascript - Jquery延迟执行脚本

javascript - JQuery Datepicker 隐藏页面上一个日历的日期

javascript - 拒绝在 chrome 中获取不安全的 header "Location",在 firefox 中没有内容

regular-language - 证明语言的连接在 Agda 中是关联的

context-free-grammar - 常规语法与上下文无关语法

javascript - 如何为每次迭代在angularjs中添加一个带有colspan的td?

java - 将显示名称字符串从 "First M. Last"更改为 "Last, First M."?

javascript - 正则表达式不允许在数字末尾有两个零

javascript - 尝试在用户键入时使用 javascript 正则表达式验证日期条目