0

Text example,

We will NOT let these Caravans, which are also made up of some very bad thugs and gang members, into the U.S. Our Border is sacred, must come in legally.

I want to replace NOT to not. But don't replace We, Caravans, U.S. Our Border.

I found this Regex replace uppercase with lowercase letters

Find: (\w) Replace With: \L$1

This replaces all the upper cases.

PS: My reason for doing this is that I use a TTS to produce sounds. NOT will be pronounced to N.O.T. I just want it to be read as not. I don't want to replace too many things. Because reader will see the text, keeping original will be good.

Administrator
  • 254
  • 1
  • 8

3 Answers3

1

Because \L before a capture group turns it to lower case in whatever your environment is, sounds like all you need to do is to find occurrences of two or more upper-case characters: match

([A-Z]{2,})

and replace with

\L$1

If you only want full words to be replaced, then add word boundaries as well:

(\b[A-Z]{2,}\b)

(you may be able to omit the capture group and use $& instead of $1)

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
0

Just in your posted question Regex replace uppercase with lowercase letters

The second answer can solve your problem

find:

([A-Z]){2,n}

replace:

\L$1
Zhang
  • 3,030
  • 2
  • 14
  • 31
0

I think I'd go with this:

(\b[A-Z]{2,}\b)

The \b is a word boundary, the [A-Z] is simply capital letters, and the {2,} is two or more.

https://regex101.com/r/qHmE1V/1

And in your replace \L$1

sniperd
  • 5,124
  • 6
  • 28
  • 44