• Login
Community
  • Login

Remove one character before a character

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 4 Posters 2.4k Views
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.
  • י
    יואב פתאל
    last edited by Jun 16, 2018, 4:59 PM

    Hi, so I have a long list separated by one character, and I need them to be separated by only one space.

    So for example, I have this:
    Test | Word
    And I want this:
    Test Word

    I can’t just replace | with blank because it will leave two spaces instead of one.
    Help?

    1 Reply Last reply Reply Quote 0
    • J
      Jon Comps
      last edited by Jon Comps Jun 16, 2018, 7:00 PM Jun 16, 2018, 7:00 PM

      If the | is always surrounded by two spaces you can replace " | " with " " (remove the speech marks they were just to highlight the use of spaces)

      Jon

      1 Reply Last reply Reply Quote 0
      • T
        Terry R
        last edited by Jun 18, 2018, 3:03 AM

        Bear in mind that the replacement string can be empty, which effectively means destroy/delete what i want to find.

        In your case however that would leave 2 spaces together. Try this:
        Find:\h|\h
        Replace:\h
        The \h looks for a space (Horizontal spacing. This only matches space, tab and line feed). So we have look for a space followed by the character I want, then another space and replace with only 1 space.

        Terry

        1 Reply Last reply Reply Quote 0
        • M
          mkupper
          last edited by Jun 18, 2018, 11:09 PM

          If you had Test | Word and replaced the | with a space then you would have three spaces, not two.

          If your list uses | as a separator and that sometimes there are one or more spaces before and/or after the | then use regular expression mode.
          Search for: \x20*\|\x20*
          Replace with: \x20

          • The first \x20* looks for zero or more leading spaces. I used \x20 rather than a space self as it’s easier to see on the screen.
          • \| looks for the |. In regular expression mode a | is special and so use \| to search for a | itself.
          • The second \x20* looks for zero or more trailing spaces.

          If your data has either one or zero spaces before and after the | and never had two or more spaces before/after the | then you can use
          Search for: \x20?\|\x20?
          Replace with: \x20

          1 Reply Last reply Reply Quote 0
          1 out of 4
          • First post
            1/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors