Splitting string into matching and non-matching groups in javascript

Viewed 1610

I am trying to split the string into an array of strings those matching a regular expression and those that don't:

string = "Lazy {{some_animal}} jumps over.."
# do some magic with regex /({{\s?[\w]+\s?}})/g and its negation
array = ["Lazy ", "{{some_animal}}", " jumps over.."]

Best performant way to do that in javascript?

2 Answers
Related