I am trying to use regex with javascript, I have the following list:
word1 @['id1', 'name1']@ @['id2', 'name2']@ @['id3', 'name3']@ word2 @['id4', 'name4']@ word3 @['id5', 'name5']@
I want to detect everything has: @[' ..... ']@ and split them like that:
word1
@['id1', 'name1']@
@['id2', 'name2']@
@['id3', 'name3']@
word2
@['id4', 'name4']@
word3
@['id5', 'name5']@
So I can read the id and the name later to be able to create a link:
<a href="url/[id]">[name]</a>
I have tried this regex:
[@\['](.)*['\]@]
But it is just mark everything from the first @[' till the end at name5.
Simple code:
const reg = /[@\['](.)*['\]@]]/;
const arr = content.split(reg);
If anybody knows how to split it, I would appreciate sharing the solution. Thank you!