I have a string with multiple substrings of the format {{******}}
where *****
can be a couple things. I'm trying to split my string so that the resulting array contains the substrings before and after these substrings, as well as the full substrings themselves.
I've created a regular expression that works here: https://regex101.com/r/I65QQD/1/
I want the resulting array when I call str.split(...)
to contain the full matches as seen in the link above. Right now it is returning subgroups so my array looks really weird:
let body = "Hello, thanks for your interest in the Melrose Swivel Stool. Although it comes in 2 different wood finishes, there aren't any options for the upholstery fabric. {{youtube:hyYnAioXOqQ}}\n Some similar stools in different finishes are below for your review. I hope this is helpful to you!\n\n{{attachment:2572795}}\n\n{{attachment:2572796}}\n\n{{attachment:2572797}}\n\n{{attachment:2572798}}\n";
let bodyComponents = body.split(/{{attachment:([\d]+)}}|{{(YOUTUBE|VIMEO):([\d\w]+)}}/i);
console.log(bodyComponents);
Is there any way to have the resulting array contain the full matches instead of the subgroups? So that it looks like this:
[
"Hello, thanks for your interest in the Melrose Swivel Stool. Although it comes in 2 different wood finishes, there aren't any options for the upholstery fabric. ",
"{{youtube:hyYnAioXOqQ}}",
...
]
Thanks