Javascript正则表达式匹配字符串中的空格,但忽略HTML标记中的空格?

Javascript正则表达式匹配字符串中的空格,但忽略HTML标记中的空格?,javascript,html,regex,Javascript,Html,Regex,示例字符串: <div class="test">Hey </div> http://www.w3schools.com/html <a href="http://www.w3schools.com/html/">Visit our HTML tutorial</a> hello cool world 嘿http://www.w3schools.com/html 你好酷世界 我需要一些正则表达式来按空格分割字符串,得到如下结果: ['<

示例字符串:

<div class="test">Hey </div> http://www.w3schools.com/html <a href="http://www.w3schools.com/html/">Visit our HTML tutorial</a> hello cool world
嘿http://www.w3schools.com/html  你好酷世界
我需要一些正则表达式来按空格分割字符串,得到如下结果:

['<div class="test">Hey </div>', 'http://www.w3schools.com/html', '<a href="http://www.w3schools.com/html/">Visit our HTML tutorial</a>', 'hello', 'cool', 'world']
['Hey','http://www.w3schools.com/html'你好','酷','世界']
已经找到了一些正则表达式,但它匹配HTML标记之间的空格

\s(?=[^>]*(?:<|$))

\s(?=[^>]*(?:尝试以下解决方案

var str = '<div class="test">Hey </div> http://www.w3schools.com/html <a href="http://www.w3schools.com/html/">Visit our HTML tutorial</a> hello cool world';
var pattern = /((<([^>]+)>+([^>]+)+<([^>]+)>)|\b([^><\s]+)\b)/g;
var result;

result = str.match(pattern);

console.log(result);
var str='嘿http://www.w3schools.com/html  你好酷世界';

var pattern=/((]+)>+([^>]+)+]+)\b([^>你也应该展示你的尝试,这样我们可以帮助你找到解决方案,你不能只是把任务分配给我们,这就是为什么你不断获得选票的原因。谢谢你)补充了目前遇到的问题(一见钟情就很好用=)