• Login
Community
  • Login

add characters

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 2 Posters 487 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.
  • M
    Mr Schnok
    last edited by Mar 10, 2023, 9:32 AM

    Hello,

    I have a file of 160 000 lines with some empty lines.
    I would like to add characters at the beginning of each line, but not when they are empty. I found how to add characters at the beginning or end of the line, but I don’t know the regular expression syntax to go further.
    Could someone help me please?

    Thank you in advance.

    1 Reply Last reply Reply Quote 0
    • G
      guy038
      last edited by guy038 Mar 10, 2023, 10:25 AM Mar 10, 2023, 10:03 AM

      Hello, @mr-schnok and All,

      Not difficult !

      SEARCH (?x) ^ (?! \R )    OR    ^(?!\R)

      REPLACE Your text to insert at BEGINNING of NON-EMPTY lines


      The search regex means :

      Change any beginning of line ( ^ ) with the text to replace, but ONLY IF not immediately followed with a line-break character, as \R represents, either \r\n or \r or \n

      Best Regards

      guy038

      1 Reply Last reply Reply Quote 1
      • G
        guy038
        last edited by guy038 Mar 10, 2023, 10:27 AM Mar 10, 2023, 10:19 AM

        Hi, @mr-schnok and All,

        Oh… I did not notice that you spoke about adding characters at the end of non-empty lines as well !

        In this case, the regex S/R becomes :

        SEARCH (?x-s) (?<= . ) $    OR    (?-s)(?<=.)$

        REPLACE Your text to insert at END of NON-EMPTY lines


        The search regex means :

        Change any end of line ( $ ) with the text to insert, but ONLY IF immediately preceded with a standard character ( . )

        BR

        guy038

        M 1 Reply Last reply Mar 10, 2023, 11:19 AM Reply Quote 2
        • M
          Mr Schnok @guy038
          last edited by Mar 10, 2023, 11:19 AM

          Hello @guy038

          Thank you very much. It works very well.
          And especially thank you for the explanation.

          Have a nice day.
          Phil

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