【发布时间】:2021-02-04 11:39:46
【问题描述】:
我想在单词之间进行拆分,但不在“@%5967411b349:Jean leo%”标签内。
如何解决?
let title = "Hello everyone @%5967411b349:Jean leo% and @%5995006d0d:David Leong% wish you have a good day with <audi <samsung and #canon";
const formatTitle = (title) => {
const results = []
title.trim().split(" ").map(title => {
if (title.indexOf("#") === 0) {
results.push(title)
results.push(" ")
}
else if (title.indexOf("<") === 0) {
results.push(title)
results.push(" ")
}
else if((title.indexOf(title)) === 0)
{
let userTag = title.replace(/[@%]*/g, '').split(':');
results.push(title)
results.push(" ")
}
else {
results.push(`${title} `)
results.push(" ")
}
})
return results
};
formatTitle(title)
预期输出:大家好@Jean leo @David Leong 祝您与
【问题讨论】:
标签: javascript arrays reactjs string ecmascript-6