Skip to content

Instantly share code, notes, and snippets.

@smallnewer
Created September 22, 2013 08:01
Show Gist options
  • Save smallnewer/6657798 to your computer and use it in GitHub Desktop.
Save smallnewer/6657798 to your computer and use it in GitHub Desktop.
以特殊符号分割指定字符串。具体描述见评论
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div>\||di\|v|ab\@ca@大点的a:吧啊</div>
<script>
var str = document.querySelector("div").innerHTML;
// alert(str)
var reg = /((?:.*?(?:\\[\|\:\@])*)[^\\]*?)([\|\:\@]|[^\|\:\@]$)/gi;
var ret = [];
var length = str.length;
str.replace(reg,function ($,$1,$2,ind) {
console.log(arguments);
if (ind + $.length < length) {
$ = $.slice(0,-1);
};
ret.push($);
})
console.log(ret);
</script>
</body>
</html>
@smallnewer
Copy link
Author

上述代码尚未完成,暂作记录

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment