Javascript RegExp:按“拆分行”&引用;

Javascript RegExp:按“拆分行”&引用;,javascript,regex,regular-language,Javascript,Regex,Regular Language,如何转换 "one,cubic-bezier(0, 0, 1, 1), cubic-bezier(0, 0, 1, 1), linear" 到 怎么做 JavaScript 这是不一样的。因为有引号(左边和右边),这里是(-left,)-right 不要在JS中工作 'ease,cubic-bezier(0, 0, 1, 1), linear,2,3'.split(/,(?=[^()]*((|$))/gi); 结果: ease,(,cubic-bezier(0, 0, 1, 1),, li

如何转换

"one,cubic-bezier(0, 0, 1, 1), cubic-bezier(0, 0, 1, 1), linear"

怎么做

JavaScript

这是不一样的。因为有引号(左边和右边),这里是(-left,)-right

不要在JS中工作

'ease,cubic-bezier(0, 0, 1, 1), linear,2,3'.split(/,(?=[^()]*((|$))/gi); 
结果:

ease,(,cubic-bezier(0, 0, 1, 1),, linear,,2,,3

假设paren不能嵌套(在这种情况下,您将无法使用JS regex flavor)

试试这个:

,(?![^()]*\))
快速细分:

,          # 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
用通俗易懂的英语,应该是:

匹配逗号[1],前提是[2]前面没有结束符[4],且逗号和结束符[3]之间没有结束符


假设paren不能嵌套(在这种情况下,您将无法使用JS regex flavor)

试试这个:

,(?![^()]*\))
快速细分:

,          # 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
用通俗易懂的英语,应该是:

匹配逗号[1],前提是[2]前面没有结束符[4],且逗号和结束符[3]之间没有结束符

根据您的示例:

var str = "one,cubic-bezier(0, 0, 1, 1), cubic-bezier(0, 0, 1, 1), linear";
var arr = str.split(/,\s*(?!\s*\d)/);
console.log(arr.toSource());

// result
// ["one", "cubic-bezier(0, 0, 1, 1)", "cubic-bezier(0, 0, 1, 1)", "linear"]
以下是基于您的示例的

var str = "one,cubic-bezier(0, 0, 1, 1), cubic-bezier(0, 0, 1, 1), linear";
var arr = str.split(/,\s*(?!\s*\d)/);
console.log(arr.toSource());

// result
// ["one", "cubic-bezier(0, 0, 1, 1)", "cubic-bezier(0, 0, 1, 1)", "linear"]

这是什么语言?java,bash…?我不同意复制品。字符串非常简单,这里我们要分析一种结构化语言(如何管理嵌套括号?)输入是否包含一个以上的()级别?在JS中不起作用ease,cubic bezier(0,0,1,1),linear,2,3'.split(/,(?=[^()])*((|$)/gi);Result:ease,(,cubic bezier(0,0,1,1),,linear,,2,3什么语言?java,bash…?我不同意重复。字符串非常简单,这里我们要解析一种结构化语言(如何管理嵌套括号?)输入是否会包含多个级别的()?在JS中不起作用。'ease,cubic bezier(0,0,1,1),linear,2,3'。拆分(/,(?=[^()]*((|$))/gi);结果:ease,(,cubic bezier(0,0,1,1),linear,,2,3