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?
11 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):
Screenshot (after):
3