Match range without duplicating

Match range without duplicating



I need to match 1/1 all the way through 4/48. 1/1,1/2,1/3 all the way through 1/48,2/1 through 2/48 ....3/1 through 3/48 and 4/1 through 4/48.... but having a hard time with the regex as it must not contain a comma at the end and not duplicate any thing that was already input.


^([1-4]/([1-9]|[1-4][0-8]|[1-3][0-9]))[?,]+$






Regular expressions may not be the right tool for this. Have you considered parsing the string yourself instead?

– Paul Benn
Sep 18 '18 at 14:09






While I have not downvoted, as I read thru the comment thread below, I'll say this is not a well thought out question. For all the exceptions you have listed, you should compose a question that has an easy to use test suite of data that covers all of the cases you need to cover. Note that this doesn't mean we need to see all your data, but just enough of each unique type to compose a solution that will work for a small data set or your complete data set.

– shellter
Sep 21 '18 at 15:08






Also, rather than make people guess what tool you are using, you should state something like "I am coding this in python", AND you should include a tag for your language/tool. Finally, with sample data and expected output we might be able to suggest an alternate solution. As @PaulBenn says, RegEx might not be the right solution for this problem. Please read the help center and especially Minimal, Complete, and Verifiable example before posting more Qs here. Good luck.

– shellter
Sep 21 '18 at 15:10





1 Answer
1



To match numbers from 1 to 48


1


48


1


9


[1-9]


10


39


[1-3][0-9]


40


48


4[0-8]



which gives


[1-9]|[1-3][0-9]|4[0-8]



Update from comments, the following regex


^(?:(?:^|,)[1-4]/(?:[1-9]|[1-3][0-9]|4[0-8])(?=,|$))+$



About non-capturing group and lookaheads.


(?:


)


(


)


(?:,)


,


(?=,)


,






I have something similar but I dont have it working so that it avoids duplicates and does not contain comma at end of string.. ^([1-4]/([1-9]|[1-4][0-8]|[1-3][0-9]))[?,]+$

– momk
Sep 18 '18 at 14:31







the order matters in your expression you have [1-4][0-8] which matches from 10 to 48 except 19,29,39 and then [1-3][0-9] which matches from 10 to 39

– Nahuel Fouilleul
Sep 18 '18 at 14:33


[1-4][0-8]


[1-3][0-9]






So far I have this: ^([1-4]/([1-9]|[1-3][0-9]|4[0-8])?,)[^,]+$

– momk
Sep 18 '18 at 14:33






why downvote. i pasted what i had so far. ridiculous...

– momk
Sep 18 '18 at 15:08






for info, i'm not the downvoter

– Nahuel Fouilleul
Sep 18 '18 at 15:17



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế