• Login
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 728 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.
  • J
    JustinJudo
    last edited by JustinJudo Jul 4, 2023, 8:07 PM Jul 4, 2023, 8:04 PM

    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?

    P 1 Reply Last reply Jul 4, 2023, 9:26 PM Reply Quote 0
    • P
      PeterJones @JustinJudo
      last edited by PeterJones Jul 4, 2023, 9:26 PM Jul 4, 2023, 9:26 PM

      @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
      J 1 Reply Last reply Jul 5, 2023, 12:20 AM Reply Quote 2
      • J
        JustinJudo @PeterJones
        last edited by Jul 5, 2023, 12:20 AM

        @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
        1 out of 3
        • First post
          1/3
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors