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.

2
  • 2
    post your attempts. Commented Nov 2, 2018 at 3:15
  • @AvinashRaj, My reason? Commented Nov 2, 2018 at 3:20

3 Answers 3

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)

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.