The header question may not be easy to understand. Hope you can understand my detailed info below.
I have sentence data below, that has some tags, represented by [tn]tag[/tn]
:
const sentence = `[t1]Sometimes[/t1] that's [t2]just the way[/t2] it has to be. Sure, there
were [t3]probably[/t3] other options, but he didn't let them [t4]enter his mind[/t4]. It
was done and that was that. It was just the way [t5]it[/t5] had to be.`
And i have parts of the sentence.
const parts = [
"Sometimes that's just the way",
"it has to be",
"Sure,",
"there were probably other options,",
"but he didn't let them enter his mind.",
"It was done and that was that.",
"It was just the way it had to be."
];
Goal is to add tags on each parts using the sentence above.
const expectedOutput = [
"[t1]Sometimes[/t1] that's [t2]just the way[/t2]",
"it has to be",
"Sure,",
"there were [t3]probably[/t3] other options,",
"but he didn't let them [t4]enter his mind[/t4].",
"It was done and that was that.",
"It was just the way [t5]it[/t5] had to be."
];
What I've tried so far are the following, but seemingly does not make sense, and I endup nothing.
- make a clone sentence, and remove all tags. (code below)
- find all parts in the sentence.
- [problem is I don't know how to put again the tags]
I wanna ask is there any chance to achieve it? and how. thanks
export const removeTags = (content) => {
content = content.replace(/([t]|[\/t])/g, '');
return content.replace(/([t\d+]|[\/t\d+])/g, '');
};