Tinderbox Forum

String manipulation: How do I extract the first and last name from a "last name, first name" string?


I am stuck - I have lots of notes in a container that (since imported from an Excel spreadsheet) have names of persons as their $Name. They are in the format “last name, first name” (i.e. “Smith, Henrietta”).

Now I need to extract the first and last names (and drop the comma in the process).

I thought that the new TBX 9.1 operator .extract(pattern) would help, but
a) I don’t know what precise parameters it takes, and
b) no idea about the pattern I need to apply.

Grateful for any help from RegEx and other wizards!


I’d approach this as:


This won’t handle names like “Martin Luther King, Jr.” or “Nampeyo”, but it should handle many cases. I’m sure others will have nicer solutions!

1 Like

Thanks, Mark! I spent about an hour trying to solve it by means of RegEx - your approach is much simpler. And it works. (May not work for “Martin Luther King, Jr.”, but it did work with the most complicated name I had in my list, namely “Dijon de Monteton, Charles Philippe Graf de” which it split effortlessly :wink:

1 Like

Falsehoods We Believe About Names. I changed the word ‘Programmers’ in the linked article to ‘We’, as I think we are all prone to both innocent and lazy assumptions.

Depending on what we, individually, need to do with name informations, it may prove useful to make $FirstName, $KnownName, $LastName, ($FullName) $PreNominal and $PostNominal attributes. Techniques like above (.split()) will cover most bases—at least for names in many Western counties whist the other attributes might take more ‘manual’ inspection and triage.

Consider Ted Nelson, who gave us the word ‘hypertext’:

$FullName = "Theodor Holm Nelson";
$FirstName = $FullName.split(" ").at(0);
$LastName = $FullName.split(" ").at(-1); // -1 is the last item in a list
$KnownName = "Ted";

He has a PhD so we might want to add:

$PreNominal = "Dr.";
$PostNominal = "PhD";

You might then want a boolean as to whether the person uses their pre-/post-nominals in general communication.

Names matter, as the citizens of Pittsburgh might attest.


1 Like

Mark - thank you! Indeed this is what I also added to the TBX file I am working on (I have to keep a long list of people, of whom only a subset have agreed, current with respect to those who did agree; and I need to be able to output them in both “Full Name” and “Last Name, First Name” formats).

Many thanks for being so unfailingly helpful. So as a little thank you - and because you mentioned Ted Nelson - here is my favourite anecdote about him. It happened when (almost 20 years ago) I was an associate member of the Oxford Internet Institute (OII). Back then, Bill Dutton - the founding director - had brought Ted Nelson in as a visitor, and we all enjoyed his company. Of course he was famously absent-minded (constantly thinking about Xanadu wears you down), and when the wife of one of the OII professors (Yorick Wilks) bumped into him in the North Oxford shops, she was not sure he knew who she was. “I’m Yorick’s wife!” she therefore said to him. But rather than clearing the puzzlement from his face, it did the opposite - and he responded: “You’re my ex-wife?!”
Ted himself relayed the story at some meeting, and you can imagine the laughter it caused. So, professors may be absent minded, but Ted surpasses them all!

1 Like

Names are a great example of a situation in which you can go a long way with a combination of a naïve solution and manual correction. A big database must be designed for all the bad cases, but sometimes it’s enough for one’s notes to automate the common situation and fix what goes wrong in unusual cases.

I have my own Ted story, happily told to my own embarrassment. At a Tinderbox weekend meet-up c.2009(?) Mark B asked me if I’d help look after an ageing but important visitor who’d be sitting in: a guy called Ted Nelson. So I googled Ted Nelson and despite having sued the Net pre Web and then the Web, my mind didn’t make the association. Anyway, I had a lovely day chaperoning a guy who had opinions and also politely informed all my mine were…plain wrong (but in a way that didn’t cause me offence).

Of course, since then I’ve filled that gap and one of my many side-projects is digitising some of Ted’s books. Although Computer Lib/Dram Machines has been reproduced (here), his wonderful Literary Machines being self-published and is now hard (and expensive) to obtain, as is The Home Computer Revolution which hopefully soon may both re-appear as ebooks. My pitch to Ted—he was initially resistant— was that it not just the sales (I hope there will be some, despite e-piracy) but to get his work before the eyes of the post-Web, post-paper generations. Indeed, I’m trying to make an eBook version that has all the major editions either in the book (electronic pages are cheap) and perhaps with commentaries from some Net/Web/Hypertext luminaries as to how Ted’s ideas influenced their work. :slight_smile:

†. Understandably as ebooks are Web-style hypertext and not like Xanadu.

Great story, Mark! And Ted is really special - I assume his idiosycrasies will not have diminished in almost 20 years :wink: And the projects you’re undertaking are really of great importance! I look forward to the results.
I treated myself to his autobiography last year, “Possiplex”. Just great reading if one is interested in the cultural history of the web, which I very much am.

1 Like

My favourite heading from Possiplex is p.260: “Race Driving or Sex Workshops? (July 1988)”. My life, by comparison, has been remarkably dull.

† At the time, I was an instructor at RMAS Sandhurst, UK’s equivalent of West Point. Not quite the same West Coast vibe, though actually remarkably good fun as a posting.

1 Like