• Login
Community
  • Login

REGEX: Add something at the beginning of each line that does not contain the sign -

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 275 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.
  • R
    Robin Cruise
    last edited by Robin Cruise Apr 20, 2021, 8:27 AM Apr 20, 2021, 8:25 AM

    I want to add something to the beginning of each line that does not contain the sign -

    My regex is not so good:

    FIND: ^(?!\-)
    REPLACE BY: ANYTHING

    1 Reply Last reply Reply Quote 0
    • R
      Robin Cruise
      last edited by Robin Cruise Apr 20, 2021, 8:27 AM Apr 20, 2021, 8:26 AM

      Got it. There was no need for \ before -

      FIND: ^(?!-)
      REPLACE BY: ANYTHING

      1 Reply Last reply Reply Quote 0
      • A
        Alan Kilborn
        last edited by Apr 20, 2021, 12:12 PM

        So for future people that come along looking maybe for a solution to something, and seeing this post, I say: It has several pieces of misinformation.

        First, the “spec” was:

        add something to the beginning of each line that does not contain the sign -

        In fact, the regex supplied does not do this. What it does is: Add something to the beginning of each line that does not start with -.

        Second, the OP diagnosed a problem as being that:

        There was no need for \ before -

        In fact, the removal of \ did nothing to change the outcome of the replacement operation. - does not need to be “escaped” in the usage shown by the OP. While it was true that there was “no need”, it didn’t make the first regex not work. The two regexes supplied by the OP do exactly the same thing.

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