Change First Name SPACE Last Name to First Initial Last Name

51 views
Skip to first unread message

Bill Walker

unread,
Oct 9, 2023, 8:14:46 AM10/9/23
to BBEdit Talk
Example:  Change  John Doe to JDoe

Neil Faiman

unread,
Oct 9, 2023, 9:52:21 AM10/9/23
to BBEdit Talk Mailing List
The good people on this mailing list delight in helping other users solve problems, but before they can help solve a problem, the problem has to be well defined.

I’m guessing that you have one or more files containing one or more two-word names that you want to transform, But how are the names that are to be transformed distinguished from all the other word pairs in your files?` That is the key question, and there isn’t even a hint at an answer in your problem statement.

Regards,
Neil Faiman

Kjetil Rå Hauge

unread,
Oct 9, 2023, 10:46:48 AM10/9/23
to BBEdit Talk
Try this:
- Click Case sensitive and Grep
- Find: "([A-Z])([a-z]+.) ([A-Z][a-z]+)."
- Replace: "\1\3\4 "
________________________________________
From: bbe...@googlegroups.com <bbe...@googlegroups.com> on behalf of Bill Walker <bwa...@cleanair.com>
Sent: 09 October 2023 04:32
To: BBEdit Talk
Subject: Change First Name SPACE Last Name to First Initial Last Name

Example: Change John Doe to JDoe

--

Benjamin Irwin

unread,
Oct 9, 2023, 3:10:04 PM10/9/23
to BBEdit Talk
That's cool but I had to move one of the periods inside the ")" as follows.

Find:  ([A-Z])([a-z]+.) ([A-Z][a-z]+.)

Replace:  \1\3\4

Tim A

unread,
Oct 10, 2023, 4:09:02 PM10/10/23
to BBEdit Talk

Find:         ([A-Z])([a-z]+.) ([A-Z][a-z]+.)

Replace:   \1\3\4

Why the "+."?     Isn't the space between first and last name all that is needed?

And what is \4   mean with only three captures?

Bruce Van Allen

unread,
Oct 10, 2023, 5:41:42 PM10/10/23
to bbe...@googlegroups.com
The ‘+’ is quantifying a character class '[a-z]’.

‘[a-z]+’ (without the quotes) means one or more characters in the range ‘a’ to ‘z’.

The ‘.’ just adds one more character, and isn’t needed.

And Tim is correct that there’s no fourth capture, so the ‘\4' is meaningless.

— Bruce

_bruce__van_allen__santa_cruz_ca_
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/062bc74b-312b-4267-a828-52c4a081d87an%40googlegroups.com.

Message has been deleted

Tim A

unread,
Oct 10, 2023, 7:24:24 PM10/10/23
to BBEdit Talk

[a-z]+           so  this will match all the lower case letters in the first name


The ‘.’ just adds one more character, and isn’t needed." 
         - but here wouldn't it match the presumed space character between First and Last name?

... So why then can it successfully match the space character as demanded by the regular expression? Hasn't it been "used up" by the period?

Bruce Van Allen

unread,
Oct 10, 2023, 7:26:10 PM10/10/23
to 'anotherhoward' via BBEdit Talk
That ‘.’ doesn’t match the space character between first and last because that space character is in the pattern.

([A-Z])([a-z]+.) ([A-Z][a-z]+.)
^

So that ‘.’ would just be matching the last character of the first name.

HTH

— Bruce

_bruce__van_allen__santa_cruz_ca_





On Oct 10, 2023, at 4:20 PM, Tim A <timaa...@gmail.com> wrote:

([AZ])([az]+.) ([AZ][az]+.)

[a-z]+’ so this will match all the lower case letters in the first name

The ‘.’ just adds one more character, and isn’t needed." - but here would match the presumed space character between First and Last name

... So why does then successfully match the space character as demanded by the regular expression? Hasn't it been "used up" by the period?


On Tuesday, October 10, 2023 at 2:41:42 PM UTC-7 Bruce Van Allen wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/8d7a1a3c-938b-4989-9ea0-48dfc4f65dd9n%40googlegroups.com.

Bruce Van Allen

unread,
Oct 10, 2023, 7:30:37 PM10/10/23
to bbe...@googlegroups.com
Hmm, that carat ^ should have been under the spacebar space.

Anyway, to further explain: at first the regex engine will indeed match that spacebar space with the dot ‘.’. But then it comes to the actual spacebar space in the pattern, but there isn’t one left, so the regex engine backs up, matches the dot to the last character before the space, matches the space, and moves on.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/A3DDF538-CD8E-40C9-8DDE-6C8432DC0319%40cruzio.com.

Tim A

unread,
Oct 10, 2023, 7:37:40 PM10/10/23
to BBEdit Talk
Thanks for the deeper explanation.  Learned something.
The Ways of the Engine can be mysterious. 

Dim

unread,
Oct 11, 2023, 9:28:33 AM10/11/23
to BBEdit Talk
Check this one (allowing for -, ', and some accented characters):

Find: ([A-ZÀ-ÿ])\w+(-[A-ZÀ-ÿ])*\w*\b\W+([-'\w]+)\b
Replace: \1\2\3

Reply all
Reply to author
Forward
0 new messages