Community
    • Login

    Replace numbers from position 20 to 30 in the middel af a line.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    replaceregexregularposition
    4 Posts 3 Posters 16.6k Views 2 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.
    • Tino Salskov LarsenT Offline
      Tino Salskov Larsen
      last edited by

      I have a file with 10000+ lines - I know the alt+mouse to mark text in the middle of the lines, but with 10000+ lines it is difficult to concentrate to the bottom… :-)

      Can I use regular expressions or maybe a plugin to replace all number from position 20-30 in each line to 0000000000

      The represent a amount which is different in every line.

      Example file:
      777777777777777777770000052500-020161207
      888888888888888888880000013798-020161208
      999999999999999999990000175131-020131209

      My wish :-)
      777777777777777777770000000000-020161207
      888888888888888888880000000000-020161208
      999999999999999999990000000000-020131209

      1 Reply Last reply Reply Quote 1
      • PeterJonesP Online
        PeterJones
        last edited by PeterJones

        Based on your example, I assume you mean positions 21-30: i.e., keep 1-20, replace 21-30, keep anything else

        Find:      ^(.{20}).{10}
        Replace:   (\1)0000000000
        

        The parentheses in the Replace string are for readability, and could have been written as

        Replace:   \10000000000
        

        [ UPDATE: Make sure “Regular Expression” is selected. :-) ]

        Explanation: Find

        ^ = start of string
        (.{20}) = match the first twenty characters, and store them in \1 (. matches any character)
        .{10} = match the next 10 characters, and don't store them (They won't be part of the ending string
        

        Explanation: Replace

        (\1)       = recall the \1 from the match, and put the characters there
        0000000000 = put 10 raw 0s in the text
        

        The rest of the line, which isn’t part of the match, will stay as-is.

        1 Reply Last reply Reply Quote 0
        • Tino Salskov LarsenT Offline
          Tino Salskov Larsen
          last edited by

          Thank you very much, just what I needed… :-) :-)

          I have just changes 20924 lines in no time…

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

            Hello , Tino and Peter,

            Congratulations to you, both ! Tino, for nicely exposing your wish and Peter for your full explanation, about the proposed regex :-)

            An other S/R, using the \K syntax, could be :

            Find what : ^.{20}\K.{10}

            Replace with : 0000000000

            Notes :

            • As soon as the first twenty characters of the current line are matched, the \K feature forces the regex engine to forget anything previously matched and reset the regex engine position !

            • So the final match is, only, the ten characters, located between the columns 21 and 30

            • … which is, simply, changed into the 0000000000 string :-)

            Remark :

            • You must use the Replace All button, only. The step by step replacement, with the Replace button, does NOT work, when the search regex contains a \K form !

            Best regards,

            guy038

            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