Regex: Change to lowercase all the words that have uppercase letters from title html tag (except the first letter)

I want to use regex to change to lowercase words that have uppercase letters

<title>THE CHILDREN are at home.</title>

TO BECOME

<title>The children are at home.</title>

So, I made a Python script that does the job:

page_title = 'THE CHILDREN are at home.' title_words = page_title.split(' ') new_title_words = list() for w in title_words: if w.isupper(): new_title_words.append(w.lower().capitalize()) else: new_title_words.append(w) page_title = " ".join(new_title_words) print(page_title) 

But I want to use a regex formula for notepad++, instead of Python. Can anyone help me?

1

1 Answer

  • Ctrl+H
  • Find what: (?:<title>.|\G)\h*\K[A-Z]+
  • Replace with: \L$0
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

(?: # non capture group <title> # literally . # any character | # OR \G # restart from last match position ) # end group \h* # 0 or more horizontal spaces \K # forget all we have seen until this position [A-Z]+ # 1 or more capital letters 

Replacement:

\L # lowercased $0 # the whole match 

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like