# Splitting a string but keeping the delimiters?

**URL:** <https://forum.kirupa.com/t/splitting-a-string-but-keeping-the-delimiters/268877>\
**Category:** flash\
**Created:** [August 19, 2008, 10:31pm UTC](https://forum.kirupa.com/t/splitting-a-string-but-keeping-the-delimiters/268877 "2008-08-19T22:31:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrh](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@rrh](https://forum.kirupa.com/u/rrh)\
**Post date:** [August 19, 2008, 10:31pm UTC](https://forum.kirupa.com/t/splitting-a-string-but-keeping-the-delimiters/268877/1 "2008-08-19T22:31:42Z")

</div>

So, I’m splitting a string using

```auto
string.split(/[><]/);

```

So this turns something like this:

```auto
This is some text with <b>formatting</b> in it.

```

into this:

```auto
This is some text with 
b
formatting
/b
in it.

```

I would prefer if I to get something like this:

```auto
This is some text with 
<b>
formatting
</b>
in it.

```

Because then when looping through the array, it’s less ambiguous which are tags and which aren’t.

I’ve got a few ideas I could try to do this without using split, but they are all kind of awkward, and I’m hoping there’s a simple way.
