I have the following string:
"<--something--><++something++><**something**>"
The string can have an arbitrary number of "somethings" , even just once.
I need to split it like so:
["<--something-->", "<++something++>", ...]
But I don't know how to proceed best.
I would do something like string.split("><") but then I would have:
["<--something--", "++something++", ...]
And with string.split(/(><)/) I'd get:
["<--something--", "><", "++something++", "><", ...]
I can think of a few less-than-optimal solutions, but I want really elegant one.
You're not splitting the string, you are matching it.
Try this:
string.match(/<(.)\1[^>]+?\1\1>/g)
This will match <, two of a kind, then find the same two of a kind and > at the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With