0

I have a text with string content and a tag. I want to split the text into an array. I tried many ways but got some bugs @@

Input:

"This is a text with a @[name of tag](tagId). This is another @[name of another tag](tagId)"

Output:

array = ["This is a text with a ", "@[name of tag](tagId)", ". This is another " , "@[name of another tag](tagId)"]

The tag always has @[ at begin, ) at the end and ]( at between,

I tried

const str = "This is a text with a @[name of tag](tagId). This is another @[name of another tag](tagId)"
const result = str.split(/[@[)]/);
console.log(result);

But that has many issues like "", " " or missing @[ in result

Thanks for all help

  • Please show us what you've tried (at least last version). On Stackoverflow you're supposed to do that so that people can help you understand the problem with your attempt. – Jay Jul 21 '22 at 08:15
  • @Jay I updated the last result I tried. I think my regex missing some condition in that. Thank you – Dang Hoang Vu Jul 21 '22 at 08:20
  • @DangHoangVu: Does the name tag includes characters, spaces, digits etc.? Does tagId includes digits, characters, spaces etc. Can you provide the real example of whole input? – Topman Jul 21 '22 at 09:27

0 Answers0