Regex to insert a space between uppercase and lowercase letters

I have text like

CacciaMagazineOttobre2020
RumoreFebbraio2021

To add a space between letters and numbers in this way

CacciaMagazineOttobre 2020
RumoreFebbraio 2021

I use this regex

Find: ([a-z])([0-9])
Replace: \1 \2

I try to understand how insert a space between uppercase and lowercase letters to have this final output

Caccia Magazine Ottobre 2020
Rumore Febbraio 2021

I try a regex like

Find: ([a-z])([A-Z])
Replace: \1 \2

but doesn't work.

2

1 Answer

Here is a way to go:

  • Ctrl+H
  • Find what: (?<=[a-z])(?=[A-Z0-9])
  • Replace with: A SINGLE SPACE
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

(?<=[a-z]) # positive lookbehind, make sure we have a small letter before current position
(?=[A-Z0-9]) # positive lookahead, make sure we have an uppercase or a digit after

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

4

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