• Login
Community
  • Login

use regex to find based on 2 characters but only replace one

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 352 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.
  • A
    aworkerb
    last edited by Apr 28, 2021, 3:53 PM

    I’d like to find all instances of a comma that are followed by a non-whitespace character, and then replace the comma with a line break but leave the non-whitespace character alone.

    It’s easy enough to find these matches using

    [,](\S)
    

    But I can’t figure out how to only replace the comma portion of the match… or even what the name of the approach/technique is so that I can read up on it. Any advice?

    (I worked around the problem for now by replacing comma followed by space with another symbol, then replacing all commas, then replacing the other symbol with comma + space again, but that’s a workaround I’d like to skip in the future.)

    A 1 Reply Last reply Apr 28, 2021, 3:59 PM Reply Quote 0
    • A
      Alan Kilborn @aworkerb
      last edited by Alan Kilborn Apr 28, 2021, 3:59 PM Apr 28, 2021, 3:59 PM

      @aworkerb

      Very much like what was discussed HERE earlier today, so there are some links there to the docs that will help with your understanding.

      For you case I’d suggest [,](?=\S)

      Not sure why you made the comma a single thing inside the [ and ], but I didn’t change that part in my suggestion.

      1 Reply Last reply Reply Quote 3
      • A
        aworkerb
        last edited by Apr 28, 2021, 4:46 PM

        lookbehind and lookahead assertions … aren’t part of the “real” match

        That’s the concept I wasn’t able to name.

        Not sure why you made the comma a single thing inside the [ and ] …

        Because I barely know what I’m doing and was piecing it together from possibly applicable Stack Exchange posts.

        Anyway, thanks, you nailed it!

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