Community
    • 登入

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

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    3 貼文 2 Posters 378 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • aworkerbA
      aworkerb
      最後由 編輯

      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.)

      Alan KilbornA 1 條回覆 最後回覆 回覆 引用 0
      • Alan KilbornA
        Alan Kilborn @aworkerb
        最後由 Alan Kilborn 編輯

        @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 條回覆 最後回覆 回覆 引用 3
        • aworkerbA
          aworkerb
          最後由 編輯

          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 條回覆 最後回覆 回覆 引用 1
          • 第一個貼文
            最後的貼文
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors