Search code examples
regexnotepad++uppercaselowercase

Notepad++ and Regex: How to convert a uppercase sentence in a lowercase sentence?


I would like to convert my sentences from uppercase to lowercase using notepad++. If every character in that sentence is uppercase, then convert every character in that sentence to lowercase.

Example:

HOW DO OUR SENTENCE EXAMPLES HELP YOU? Whether it’s simple sentences for those just learning the English language or phrasing for an academic paper, this easy-to-use sentence generator will help you choose your words with confidence.

Result: how do our sentence examples help you? Whether it’s simple sentences for those just learning the English language or phrasing for an academic paper, this easy-to-use sentence generator will help you choose your words with confidence.

I've tried something like [A-Z][A-Z]+ and replace for \l, but it is clear that I still don't understand how it works. Can you guys help me?

Thank you!


Solution

  • You may try using

    (?-i)[A-Z][^a-z?!.]*[?!.]
    (?-i)[[:upper:]][^[:lower:]?!.]*[?!.]
    

    Replace with \L$0. Note that (?-i) is equal to setting the Match Case option in the search and replace UI window.

    Both patterns mean

    • [A-Z] / [[:upper:]] - an uppercase letter
    • [^a-z?!.]* / [^[:lower:]?!.]* - zero or more chars other than lowercase letters, ?, ! and .
    • [?!.] - a ?, ! or .

    Note that this pattern assumes the sentences do not contain abbreviations.

    See the demo screenshot:

    enter image description here