Community
    • Login

    Find and Replace

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 2.8k 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.
    • Linda DerdenL Offline
      Linda Derden
      last edited by

      Is there a way to do a replace by column number
      example - i have a txt file and i need to replace whatever characters are incolumns 220-222 in each row with —

      Is there a way to do that? regular find/replace wont work because each line is different in those spaces

      1 Reply Last reply Reply Quote 0
      • guy038G Offline
        guy038
        last edited by guy038

        Hello Linda,

        regular find/replace wont work because each line is different in those spaces

        I don’t understand very well ? May be, your text contains some tabulation character, which don’t match the same physical space length ?

        If so, I would advice you, to replace, first, any tabulation by the corresponding amount of space characters, with the menu command Edit - Blank Operations - TAB to Space

        Then, taking your previous example, just perform a simple regular search/replace operation like, for instance :

        • SEARCH = ^.{219}\K... and REPLACE = EMPTY to delete from the 220th till the 222th characters

        • SEARCH = ^.{219}\K... and REPLACE = ABC to insert a fixed string between the 220th column till the 222th column

        • SEARCH = ^.{219}\K(...) and REPLACE = [\1] to surround the characters, between the 220th and the 222th, with two square brackets

        IMPORTANT :

        Due to the special \K syntax, you must use a global replacement, clicking on the Replace All button


        If you prefer use a step-by-step replace operation, the different S/R, above, should be rewritten as below :

        • SEARCH = ^(.{219})... and REPLACE = \1 to delete from the 220th till the 222th characters

        • SEARCH = ^(.{219})... and REPLACE = \1ABC to insert a fixed string between the 220th column till the 222th column

        • SEARCH = ^(.{219})(...) and REPLACE = \1[\2] to surround the characters, between the 220th and the 222th, with two square brackets

        Hope that helps you a bit !

        Best Regards,

        guy038

        P.S. :

        The nice thing, about the \K syntax, is that anything that matched before the \K form, is forgotten by the regex engine! So, in the examples above, the matched string (...) is, ONLY, the three characters, at positions 220, 221 and 222 :-)

        1 Reply Last reply Reply Quote 0

        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