Community
    • Login

    add characters

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 2 Posters 473 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.
    • Mr SchnokM
      Mr Schnok
      last edited by

      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
      • guy038G
        guy038
        last edited by guy038

        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
        • guy038G
          guy038
          last edited by guy038

          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

          Mr SchnokM 1 Reply Last reply Reply Quote 2
          • Mr SchnokM
            Mr Schnok @guy038
            last edited by

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