#1 2021-07-29 19:50

loungebob
Member
Registered: 2015-09-29
Posts: 45

Capitalize the next char after "Mc" or "Mac"

I hate regex. Well, it hates me. So it seems mutual.

Tried this

Expression: \bMc(\l)
Replace: Mc\U($1)

Tought it would upper all the Scottish names (like McDonalds, McCoy, McScott.....) but it didnt. Probably not even close. Cause I dont know what I do lol.

Anyone know the proper regex for this?

Also, for MacIntosh, LeMans etc. But I can adapt that myself. I think.

Offline

#2 2021-07-29 20:56

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Capitalize the next char after "Mc" or "Mac"

You are very close.


FROM:
Mcdonalds, Mccoy, Mcscott.
TO:
McDonalds, McCoy, McScott.

TRY:
https://www.den4b.com/wiki/ReNamer:Rules:RegEx
1) Regular Expressions: Replace expression "\bMc(.)" with "Mc\U$1" (case sensitive) (skip extension)



Explanations:
https://www.den4b.com/wiki/ReNamer:Regular_Expressions

\b >> word boundary
Mc >> literal text
. >>> one sign of any character (the symbol is just a dot)
() >> Subexpression, here for to store for later reuse
\U >> Convert all following characters to uppercase.
$1 >> backreference what was matched in subexpression





 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2021-07-29 21:14

loungebob
Member
Registered: 2015-09-29
Posts: 45

Re: Capitalize the next char after "Mc" or "Mac"

I take solace in the fact that I have various other skills. Even if my incapability in regex makes me sad.

thanks mate, works perfectly!

Offline

#4 2021-07-29 23:02

loungebob
Member
Registered: 2015-09-29
Posts: 45

Re: Capitalize the next char after "Mc" or "Mac"

So, Macy Gray becomes MacY Gray lol. Do I just add this as an exception (e.g. revert it back to Macy at the end of all actions) or is there a more elegant way to eliminate those - probably rare - instances?

Offline

#5 2021-07-30 11:11

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Capitalize the next char after "Mc" or "Mac"

loungebob wrote:

Tought it would upper all the Scottish names (like McDonalds, McCoy, McScott.....)

loungebob wrote:

So, Macy Gray becomes MacY Gray


FROM:
Macy Gray is great Machurike macher machu macy machurry.
TO:
Macy Gray is great MacHurike MacHer machu macy MacHurry.

TRY:
https://www.den4b.com/wiki/ReNamer:Rules:RegEx
1) Regular Expressions: Replace expression "\bMac(.{3,})" with "Mac\u$1" (case sensitive) (skip extension)


\bMac(.{3,}) >>> for to match "Mac" plus at least 3 of any signs.
In the replacement use then lower case u instead of upper case U.


https://www.den4b.com/wiki/ReNamer:Regular_Expressions
\U    >> Convert all characters to uppercase.
\u    >> Convert only the first character to uppercase.


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#6 2021-07-30 22:13

loungebob
Member
Registered: 2015-09-29
Posts: 45

Re: Capitalize the next char after "Mc" or "Mac"

More brilliance! Thank you very much Stefan!

Offline

#7 2021-07-30 22:16

loungebob
Member
Registered: 2015-09-29
Posts: 45

Re: Capitalize the next char after "Mc" or "Mac"

And in a quiet minute I’ll try to understand how and why it works :-)

Offline

Board footer

Powered by FluxBB