# Split a string on the \*first\* space?

**URL:** https://community.mp3tag.de/t/split-a-string-on-the-first-space/8520
**Category:** Support
**Created:** [June 28, 2009, 5:52am UTC](https://community.mp3tag.de/t/split-a-string-on-the-first-space/8520 "2009-06-28T05:52:37Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [June 28, 2009, 5:52am UTC](https://community.mp3tag.de/t/split-a-string-on-the-first-space/8520/1 "2009-06-28T05:52:37Z")

</div>

I use the following regex (probably in a FAQ somewhere) for splitting names into a first and last name, to create 'Firstname, Lastname' ARTISTSORT fields:

^(.+)\s(.+)$ -\> $2, $1

This works well for most names, even those where the artist has a middle name, since it splits on the last space in the string:

John Lee Hooker --\> Hooker, John Lee

The trouble is that it doesn't handle cases where an artist has a two words in their last name, e.g.

Townes Van Zandt --\> Zandt, Townes Van

This should instead be

Van Zandt, Townes

So I need a regex that will split strings on the first space instead of the last.

---

_[View the full topic](https://community.mp3tag.de/t/split-a-string-on-the-first-space/8520)._
