Auto-fix option for double-caps

Everything related to our flagship word processor.
Post Reply
editor10
Posts: 35
Joined: 2010-09-18 12:24:52

Auto-fix option for double-caps

Post by editor10 »

Could an option be added to Quick-fix to correct instances of double capitalization, such as this: NEw YOrk.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Auto-fix option for double-caps

Post by martin »

Nisus Writer has such an option (in our QuickFix preferences), but only for text that occurs at the start of a sentence. I can see how this correction might be useful elsewhere. Thanks for the suggestion.
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Re: Auto-fix option for double-caps

Post by Vanceone »

I would love that option, but also allow it to ignore a whitelist or something. Or at least check if the word is all caps before correcting it.
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Auto-fix option for double-caps

Post by xiamenese »

Reviving this thread, has there been any progress on this? I have been able to construct RegEx find strings which work… for NWP:

Code: Select all

\<(\p{Upper})(\p{Upper})(\p{Lower}+)
or for other PCRE-using apps

Code: Select all

\b([A-Z])([A-Z])([a-z]+)
but I can't find a way to replace the second found with its lowercase equivalent. Do any of you coding gurus know the answer, or is it just not possible to do?

:)

Mark
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Auto-fix option for double-caps

Post by martin »

xiamenese wrote: 2023-01-26 08:26:20 I can't find a way to replace the second found with its lowercase equivalent. Do any of you coding gurus know the answer, or is it just not possible to do?
Hi Mark! This is definitely possible. You want to use the "Transform" regex features in Nisus Writer with the following replacement expression:

Code: Select all

\1\T{lowercase:\2}\3
You can see that the back-reference \2 has a lowercase transform applied.

I do have one irrelevant improvement for you, if you'll be patient with me :) My personal goal with find patterns is always to replace the least amount of text possible. There's a variety of reasons for this, but the main one is you don't have to worry about disrupting non-uniform formatting. That's unlikely to be an issue here within a single word, but it's a good default workflow.

With that in mind you can use regex lookahead and lookbehind features (Nisus Writer calls these FollowedBy and PrecededBy) to avoid replacing the text around the 2nd capital letter. Here's the find pattern that only matches the single capital letter you want to transform:

Code: Select all

(?<=\p{Upper})(\p{Upper})(?=\p{Lower}+)
The replacement pattern is:

Code: Select all

\T{lowercase:\1}
I hope that helps!
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Auto-fix option for double-caps

Post by xiamenese »

Thanks Martin,

Of course your least-amount-of-text solution works beautifully. I haven't tested your first replace string—I've been busy, particularly having just taken delivery of a M2 Pro Mac Mini, which I've been setting up to replace the iMac—but I'm sure it will work. My task will be to work out how to accomplish them in PCRE RegEx. But that's my problem!

:D

Mark
Post Reply