Want all numbers sepearetly in different lines as output excluding duplicates - please help me with any regular exp for this
-
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 -
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
-
I assume the goal should be to have no duplicates in the output.
-
@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.
-
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.