Change random uppercase words to lower case

76 views
Skip to first unread message

Andy Nickless

unread,
Jun 13, 2023, 8:25:02 AM6/13/23
to BBEdit Talk
I have some text with random uppercase words (for emphasis) and I want BBEdit to find them and replace them with lower case words.
I ONLY want to change words in which ALL the letters are uppercase - in other words, leave the capital letters at the beginning of sentences and names etc.

As an example, if my sentence is:
The BIG CAT called George, sat on the DARK BROWN mat.

I would like it to look like this:
The big cat called George, sat on the dark brown mat.

Any help with this will be greatly appreciated.
Andy

Kaveh Bazargan

unread,
Jun 13, 2023, 8:42:14 AM6/13/23
to bbe...@googlegroups.com
Try this:

search: \b([A-Z]+)\b
replace: \L\1

case sensitive

--
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/506999f0-7cce-435b-beaf-d5b0ca197b47n%40googlegroups.com.


--
Kaveh Bazargan PhD
Director
Accelerating the Communication of Research
  https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/

Andy Nickless

unread,
Jun 13, 2023, 9:40:23 AM6/13/23
to BBEdit Talk
Thanks once again, Kaveh.

I tried the search:  \b([A-Z]+)\b
and replace: \L\1
It left two word spaces before the lowercase word.

When I changed the search to:  ([A-Z]+) with word spaces before and after, it did a great job as long as I used the Replace & Find button, but it had one or two quirks. For instance, if you had consecutive uppercase words, it would only find alternate ones.
Also, it didn't find capitalised words with commas, full-stops exclamation marks or question marks. That would be useful.
Lastly, it also found the word I (capitalised, of course) which I didn't want it to.

I hope I'm not being too greedy!
Thanks so much for your help so far, it's saved me quite a lot of time.

Kaveh Bazargan

unread,
Jun 13, 2023, 10:21:50 AM6/13/23
to bbe...@googlegroups.com
I can look again if it helps. is the job done or useful to have these enhancements added too?

Andy Nickless

unread,
Jun 13, 2023, 12:32:09 PM6/13/23
to 'Holger Bartel' via BBEdit Talk
Hello Kaveh,
It’s an ongoing project, so if you can improve it, that would be very useful.
Best wishes,
Andy


You received this message because you are subscribed to a topic in the Google Groups "BBEdit Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bbedit/_QX5aAWOGio/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/CAJ2R9pgY7%2BFamD%2BL2jautG_Nz%2BaP09RqmiVsrDFbso%2BwBhgPpw%40mail.gmail.com.

Message has been deleted

Fletcher Sandbeck

unread,
Jun 13, 2023, 12:45:02 PM6/13/23
to bbe...@googlegroups.com
You could try modifying it like this. Changing \b to (?<=\b) makes it so the match starts at a word boundary but does not include the word boundary in the match. With the corresponding change to (?=\b) at the end of the pattern this prevents the spaces being part of the match so should prevent the alternating behavior. 

And then (?-i) tells it to be case sensitive so you don't need to worry about the dialog setting. 

Find: (?-i)(?<=\b)([A-Z]+)(?=\b)
Replace: \L\1

[fletcher]

On Jun 13, 2023, at 9:33 AM, 'Andy Nickless' via BBEdit Talk <bbe...@googlegroups.com> wrote:

Thank you Kaveh,
It’s an ongoing project, so any improvement would be very welcome.
Andy

Andy Nickless

unread,
Jun 13, 2023, 1:00:57 PM6/13/23
to BBEdit Talk
Thank you Fletcher - that's a big improvement!
It will help me a lot.
Is there a way to avoid it finding single capitals - like "I" (capital i) or "A"?
Andy

Fletcher Sandbeck

unread,
Jun 13, 2023, 1:14:45 PM6/13/23
to bbe...@googlegroups.com
You can adjust the minimum length by changing the + to {2,} which will match strings of 2 or more capital letters.

Find: (?-i)(?<=\b)([A-Z]{2,})(?=\b)
Replace: \L\1

[fletcher]


Kaveh Bazargan

unread,
Jun 13, 2023, 2:07:22 PM6/13/23
to bbe...@googlegroups.com
So any single cap letter leave as is? will that work? What will help is if you give a few examples, or put all the words that did not work so I can test it.

Andy Nickless

unread,
Jun 14, 2023, 5:28:51 AM6/14/23
to BBEdit Talk
Thanks to both Kaveh, and Fletcher for their replies.

The following works near-perfectly for me:
(?-i)(?<=\b)([A-Z]{2,})(?=\b)

It's safely saved for future use/reference too! Thanks again!
Andy
Reply all
Reply to author
Forward
0 new messages