我有一个不寻常的请求。给定一个如下所示的字符串:
var a = "This is a sentance that has many words. I would like to split this to a few lines"
我需要每五个单词插入一个“\n”。字符串 a 可以包含任意数量的字母数字字符。
有人可以告诉我如何做到这一点吗?
a.split(/((?:\w+ ){5})/g).filter(Boolean).join("\n");
/*
This is a sentance that
has many words.
I would like to split
this to a few lines
*/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)