0

I've been looking at tonnes of questions, documents and tutorials on regexp and how to split and keep the delimiter and still don't know how to do it...

This the string I have...

<span class="code special">&lt;html&gt;</span>

and I want to split it into this one...

"<span class="code special">", "&lt;html&gt;", "</span>"

So I was trying to split it on the less than and greater signs... but it works, but keeps removing the split characters...

I have this one at the moment...

'<span class="code special">&lt;html&gt;</span>'.split(/[<>]/);
ryanc1256
  • 1,025
  • 1
  • 8
  • 14
  • Which side of the split do you want the split characters to go? – Asad Saeeduddin Aug 19 '13 at 21:59
  • on the left side so I want to keep the html characters together and the html tags together... – ryanc1256 Aug 19 '13 at 22:02
  • 1
    This isn't a duplicate, because the strategy in [the other question's answer](http://stackoverflow.com/a/12001989/578288) won't work here. It tells you how to split before the `<`, but not after the `>`. I was writing up an answer when this was closed. Here's the code I produced: [jsFiddle demo](http://jsfiddle.net/roryokane/fPvYy/). In order to split *after* the `>`, I used a `replace` step to add a globally unique marker after each `>`, and then split on that marker in the `split` step. This way is kind of hacky, and it would be better to use multiple `split`s, but this works. – Rory O'Kane Aug 19 '13 at 22:23
  • @RoryO'Kane wow.... this work... you sir are my savior!... – ryanc1256 Aug 19 '13 at 22:28

0 Answers0