Community
    • Login

    add characters

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 2 Posters 903 Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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 Offline
            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

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors