Community
    • Login

    I need to insert a special character at the beginning of a line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 1.8k Views 2 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.
    • JustinJudoJ Offline
      JustinJudo
      last edited by JustinJudo

      In a simple text file, I have the following lines:

      #–output blah blah 1
      #–output blah blah 2
      #–output blah blah 3
      –output blah blah 4
      #–output blah blah 5

      I need to insert the hashtag symbol inserted at the beginning of line # 4 – but ONLY for those lines that does not start with #.

      If I do a simple find & replace operation on the two hyphens like this:

      find: –
      replace with: #–

      I get the following result which is not want I want.

      ##–output blah blah 1
      ##–output blah blah 2
      ##–output blah blah 3
      #–output blah blah 4
      ##–output blah blah 5

      Is there a RegEx solution for this?

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Online
        PeterJones @JustinJudo
        last edited by PeterJones

        @JustinJudo said in I need to insert a special character at the beginning of a line:

        Is there a RegEx solution for this?

        Yes.

        FIND = ^(?!#)
        REPLACE = #

        -> from the beginning of line, where the next character is not a hashtag, replace the beginning of the line with a hashtag

        -—

        Useful References

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • Formatting Forum Posts
        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        JustinJudoJ 1 Reply Last reply Reply Quote 2
        • JustinJudoJ Offline
          JustinJudo @PeterJones
          last edited by

          @PeterJones Thank you Peter, I appreciate the solution. Man you’re so good with this stuff… I wish I knew how to do RegEx. I’ve looked it before but it just seem so difficult to learn!

          1 Reply Last reply Reply Quote 0

          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