简体   繁体   中英

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.

Using .split when the delimiter can be escaped is hard to get right, if you take escaped backslashes into account. Easier to match everything but the unescaped delimiters.

s = "plus\\+ | qual\\= | pipe\\| | minus\\-"
result = s.match(/(?:\\.|[^\\\|])+/g)

alert result

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM