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 702 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.
    • JustinJudoJ
      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
        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
          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
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors