Home > front end >  Change specific part of a string to Title or Proper case using regex notepad
Change specific part of a string to Title or Proper case using regex notepad

Time:07-16

I'm trying to use a regex expression in Notepad to try and convert the following string:

Name = CASTFORM-1

Name = CASTFORM-2

Into

Name = Castform-1

Name = Castform-2

I'm able to find the specific characters I need by using

(?<=Name = ). ?(?=-)

However on the replace, I can't seem to find the appropriate expression. I've tried using

\U\1

But with no luck, it ends up removing the entry completely leaving just the "-1". Is this solvable?

CodePudding user response:

You can use

Find what:      (?<=Name = \w)\w*(?=-)
Replace with: \L$0

Details:

  • (?<=Name = \w) - a positive lookbehind that matches a position that is immediately preceded with Name = and a word char
  • \w* - zero or more word chars
  • (?=-) - a positive lookahead that matches a location that is immediately followed with a - char.

The \L$0 turns the found matched text into lower case.

See the demo screenshot:

enter image description here

  • Related