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
701101which 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\nJust do a search-replace-all and you will get a list of the values.
Step two is
Edit / Line Operations / Remove Duplicate LinesYou 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\nEven 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\nLike @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.
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