[英]coffee script split function based on two conditions
Trying to tweak a plugin written in coffee script. 尝试调整以咖啡脚本编写的插件。 have a condition to split a string with delimiter pipe '|'
有使用分隔符'|'
分割字符串的条件 if this pipe character is not escaped as '\\|'
如果此竖线字符未转义为'\\|'
. 。
"plus\+ | qual\= | pipe\| | minus\-".split'|'
i tried to achieve this with by adding a space .split(' |')
, but sometimes it's not true. 我试图通过添加一个空格.split(' |')
来实现这一点,但有时并非如此。
Using .split
when the delimiter can be escaped is hard to get right, if you take escaped backslashes into account. 如果您考虑了转义的反斜杠,那么在可以对定界符进行转义时使用.split
很难实现。 Easier to match everything but the unescaped delimiters. 除未转义的定界符外,更容易匹配所有内容。
s = "plus\\+ | qual\\= | pipe\\| | minus\\-"
result = s.match(/(?:\\.|[^\\\|])+/g)
alert result
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.