1

Hi I would like to replace all the "last name" instances in my text file from full upper case to Proper case. DOE to Doe or IPSUM to Ipsum as you can see below

Name = John DOE
Random info 1
Random info 2
RandomInfo

Name = Lorem IPSUM
Random info 1
Random info 2
RandomInfo

to

Name = John Doe
Random info 1
Random info 2
RandomInfo

Name = Lorem Ipsum
Random info 1
Random info 2
RandomInfo

And I would like to do that for thousands of instances like this in a text file. What do I have to "Find and replace" on Notepad++?

Thanks!

2 Answers 2

0
  • Ctrl+H
  • Find what: (?:Name =|\G(?!^)) \K(\w)(\w+)
  • Replace with: \u$1\L$2
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

(?:             # non capture group
    Name =          # literally
  |               # OR
    \G(?!^)         # restart from last match position if not beginning of line
)               # end group
                # a space
\K              # forget all we have seen until this position
(\w)            # group 1, first letter
(\w+)           # group 2, following letters

Replacement:

\u$1        # uppercased  1rst letter
\L$2        # lowercased ather letters

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

3
  • Thank you so much Toto! Much appreciated. What if I want to replace Names that have hyphens. Let's say I want to make "John DOE-DOE" into "John Doe-Doe".
    – sammods
    Feb 5, 2021 at 16:21
  • @sammodsJust change the space (before \K) into [ -]. the regex becomes: (?:Name =|\G(?!^))[ -]\K(\w)(\w+)
    – Toto
    Feb 5, 2021 at 16:33
  • Just did, big big thanks @toto
    – sammods
    Feb 5, 2021 at 17:21
1

You can use replace text (Ctrl+H) by regular expression:

enter image description here

Find : Name = (\w+) \<(\w+)
Replace : Name = \1 \L\u\2

Explanation:

Find text

  • \< matches the beginning of a word
  • (\w+) matches any sequence of word letters

Replace text

  • \L translates everything to lowercase until the end of the replacement string
  • \u translates the next letter to uppercase
  • \1 places the first captured () search group
  • \2 places the second captured () search group
2
  • Thank you so much! Much appreciated. What if I want to replace Names that have hyphens. Let's say I want to make "John DOE-DOE" into "John Doe-Doe".
    – sammods
    Feb 5, 2021 at 16:22
  • You may duplicate the last-name group twice: Find Name = (\w+) \<(\w+)-\<(\w+), replace Name = \1 \L\u\2-\L\u\3.
    – harrymc
    Feb 5, 2021 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .