Community
    • Login

    Replace numbers in scattered strings to sequential numbers..

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    replacewildcardsequential
    2 Posts 2 Posters 445 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.
    • Ryad ArlanR
      Ryad Arlan
      last edited by Ryad Arlan

      OK so the problem is as follows:
      There are strings with random values that are scattered throughout the file which i want to change to be sequential.

      Find What : “This value”:.*,
      Will find these lines but i dont know the regex to replace the numbers or how to tell it to stop after say only 20 instances.
      . Will find the end of the string and * will allow any value, a wild card (See regex wildcards)

      IE;
      “Some random thing here”:29,
      “Another random thing here”:29,
      “Something here”:29,
      “Random thing here”:29,
      “This value”:39, <!-- I want to change these to be sequential -->
      “Some here”:29,
      “Other thing here”:29,
      “Thing here”:29,
      “Some random thing here”:59,
      “Another random thing here”:23,
      “Something here”:43,
      “Random thing here”:2,
      “This value”:12, <!-- I want to change these to be sequential -->
      “Some here”:18,
      “Other thing here”:63,
      “Thing here”:63,
      …<!-- A few thousand lines of code here–>

      Thanks in advance to any replies, it isnt anything important but I hope it helps others who might be interested.
      I may not reply for some time.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Ryad Arlan
        last edited by

        @Ryad-Arlan ,

        Search/replace (regex) does not know how to count. So it cannot increment your replacement, and it cannot count how many replacements it has done.

        To do that, you need a programming language. If you use a plugin like PythonScript, you can leverage the full power of the Python language and give it the access to the contents of the Notepad++ editor window. If you’re willing to go that route, you can search the forum for add_1 and find a lot of examples for the “add_1” style of pythonscript search-and-increment-replace. For stopping after 20 instances, you can look at the optional final argument of the editor.rereplace(search, replace[, flags[, startPosition[, endPosition[, maxCount]]]]) method.

        if you have trouble customizing what you’ve seen elsewhere for your specific situation, show us what you’ve tried, and we might be able to point out where it’s gone wrong.

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