Community
    • Login

    RegEx assistance for adding a space before an Upper case letter

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 393 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Brenda Gross 0B Offline
      Brenda Gross 0
      last edited by

      I have hundreds of table column names that contain no embedded spaces. Some of the column names use an _ to separate words, some use camel case, some use a mixture. Replacing the _ with a space is easy. But how to add a space prior to any upper case character that is not the first character and is not already preceded by a space? Each column name will be on a separate line. Thanks for any help

      Example:
      Average_Balance
      SystemRate_Change
      DateClosed

      Desired Results:
      Average Balance
      System Rate Change
      Date Closed

      1 Reply Last reply Reply Quote 0
      • guy038G Offline
        guy038
        last edited by guy038

        Hello, @brenda-gross-0 and All,

        Very easy with regexes !


        • Open the Replace dialog ( Ctrl + H )

        • Un-tick all box options

        • FIND (?-i)(?<=\l)(?=\u)|_

        • REPLACE \x20

        • Tick the Wrap around option

        • Select the Regular expression search mode

        • Click, once only, on the Replace All button

        Voila !


        Notes :

        • The leading part (?-i) is an in-line modifier which force to take care about the case of letters, meaning non-insensitive search !

        • Then, due to the alternation symbol |, two individual regexes are performed, simultaneously :

          • (?<=\l)(?=\u) which searches for an empty string between a lower-case letter and an upper-case letter

          • _ which simply searches for the underline character

        • In both cases, the replacement changes the regex search with an normal space character \x20. I could have chosen to type a single space char, instead !

        • The regex search may also be expressed as a non-capturing group : (?-i:(?<=\l)(?=\u)|_), with the leading non-insensitive option

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 3

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors