• Login
Community
  • Login

Want all numbers sepearetly in different lines as output excluding duplicates - please help me with any regular exp for this

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 5 Posters 396 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.
  • V
    venkanna gajjala
    last edited by PeterJones May 8, 2024, 12:49 PM May 8, 2024, 7:30 AM

    Input

    /*/*/701101* /*/
    /*/*/686324* /*/686324* /cart/686324* /*/*/19610076* /*/19610076* /cart/19610076*
    /*/*/699670* /*/699670* /cart/699670* /*/*/19611890* /*/19611890* /cart/19611890*
    /*/*/16474108* /*/16474108* /cart/16474108* /*/*/206961* /*/206961* /cart/206961*
    /*/*/646534* /*/646534* /cart/646534* /*/*/19509746* /*/19509746* /cart/19509746*
    /*/*/505860* /*/505860* /cart/505860* /*/*/16537082* /*/16537082* /cart/16537082*
    /*/*/670479* /*/670479* /cart/670479* /*/*/19578375* /*/19578375* /cart/19578375* /*/*/683952* /*/683952* /cart/683952* /*/*/19595640* /*/19595640* /cart/19595640*
    

    Output

    701101
    686324
    19610076
    699670
    ...
    

    —

    moderator added code markdown around text; please don’t forget to use the </> button to mark example text as “code” so that characters don’t get changed by the forum

    M T 2 Replies Last reply May 8, 2024, 7:37 PM Reply Quote 0
    • G
      guy038
      last edited by May 8, 2024, 8:56 AM

      Hello, @venkanna-gajjala,

      Although I missed something obvious, I don’t clearly understand your goal because, from your example, it happens that all numbers are present three times but the number 701101 which is unique !?

      BR

      guy038

      E 1 Reply Last reply May 8, 2024, 9:32 AM Reply Quote 0
      • E
        Ekopalypse @guy038
        last edited by May 8, 2024, 9:32 AM

        @guy038

        I assume the goal should be to have no duplicates in the output.

        1 Reply Last reply Reply Quote 0
        • M
          mkupper @venkanna gajjala
          last edited by mkupper May 8, 2024, 7:38 PM May 8, 2024, 7:37 PM

          @venkanna-gajjala I would do it as two steps:

          The chews up the various that seem to prefix a numeric value and then gets a numeric value. The replacement is the numeric value followed by the CR/LF end of line characters.

          Search: (?:[ /*\r\n]+|cart/)*([0-9]+)
          Replace: $1\r\n

          Just do a search-replace-all and you will get a list of the values.

          Step two is Edit / Line Operations / Remove Duplicate Lines

          You could make step one more complicated so that it handles consecutive duplicates but you would then still need to do step two. More complicated is not better and so I would not bother, but it’s:

          Search: (?:[ /*\r\n]+|cart/)*([0-9]+)(?:(?:[ /*\r\n]+|cart/)+$1)*
          Replace: $1\r\n

          Even more complicated is to deal with non-consecutive duplicates plus you often end up needing to do the search-replace over and over until it makes no mode changes. Those solutions also tend to run into mysterious regular expression limits when dealing with large files and so I won’t go down that path.

          1 Reply Last reply Reply Quote 1
          • T
            Terry R @venkanna gajjala
            last edited by Terry R May 8, 2024, 9:45 PM May 8, 2024, 9:41 PM

            @venkanna-gajjala

            I think the regular expression below seems to work well enough.

            Using the Replace function with search mode set to regular expression we have:
            Find What:[^\d]+
            Replace With:\r\n

            Like @mkupper solution it will also require a second step of removing the duplicate lines.

            Terry

            PS it does leave an initial empty line, which I don’t think causes any problems and is easily removed as a final step.

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