13

I have looked around and found good answers but none work with notepad++, most are for java and php. I have found the search strings below but obviously I'm a noob with regex as i don't know what open/close tags are proper in notepad++.

I would like to add a space before each capital letter.

Example:

StackOverflowKegger

becomes

Stack Overflow Kegger

This is what i have found.

Find: [a-z]+[A-Z]+ Replace: $1 (there is a space before the $)

Find:

(?<!^)((?<![:upper:])[:upper:]|[:upper:](?![:upper:]))

("(\\p{Ll})(\\p{Lu})","$1 $2")

(?!^)(?=[A-Z])

Any help would be appreciated.

MojoMan
  • 131
  • 1
  • 1
  • 3

5 Answers5

25

Search string: (.)([A-Z])
Replacement: \1 \2

This doesn't insert spaces before capitals that are the first letter on their line.

Cameron
  • 96,106
  • 25
  • 196
  • 225
1

In Notepad++, do a search-n-Replace (ctrl+h), in 'find what' input '([a-z])([A-Z])' without single quotes. in 'Replace with' input '\1 \2' without quotes.

Select radio button 'Regular Expression' and make sure you Check 'Match Case' checkbox. Now find next and keep replacing. it will convert camel or Pascal case strings into words with a space before every capital letter except the first.

Hope it is helpful. I just used it with one of my tasks.

0

Find: ^([A-Z])

Replace: \1

this will add a space to the first uppercase character in notepad++ Make sure you put the space before the \1 in the replace section.

WABET : <-from WABET : <-to

jhughes
  • 11
  • 3
0

Find what: .\K([A-Z])
Replace with: $1 a space before $1 Note!!!!!! Must to check match-case see in attached photo.

enter image description here

Haji Rahmatullah
  • 390
  • 1
  • 2
  • 11
0

If you can live with a space before the first word, then this solution worked for me.

I used the following with the Regular Expression radio button checked.:

Find what: ([A-Z]) Replace With: \1

Note the leading space before the \1 in the replace

enter image description here

Dib
  • 2,001
  • 2
  • 29
  • 45
  • This will add a space before the first character of the string, this is not wanted. – Toto Jun 08 '21 at 09:07
  • Good point it will. That was not a problem for me as I can trim that off afterwards. I'll update my answer to include that caveat. – Dib Jun 09 '21 at 10:22