Reputation: 35
Let's say I have the following string:
[lorem]{lorem;ipsum;solor;sit;amet}[ipsum]<i>Lorem</i> ipsum <b>dolor</b> sit amet
What I want is an object that contains the following:
{lorem: "{lorem;ipsum;solor;sit;amet}", ipsum: "<i>Lorem</i> ipsum <b>dolor</b> sit amet"}
How would my regular expression look? Is there any way to get the inverse of this?
/\[\w+\]/g
Thanks...
Upvotes: 0
Views: 98
Reputation: 20486
Instead of creating the inverse of /\[\w+\]/g
, just use .split()
:
var string = '[lorem]{lorem;ipsum;solor;sit;amet}[ipsum]<i>Lorem</i> ipsum <b>dolor</b> sit amet'
console.log(string.split(/\[\w+\]/));
Upvotes: 1