Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about some sequences #49

Open
csarcom opened this issue Dec 3, 2019 · 1 comment
Open

Question about some sequences #49

csarcom opened this issue Dec 3, 2019 · 1 comment
Labels

Comments

@csarcom
Copy link

csarcom commented Dec 3, 2019

Hello @asciimoo

I'm having problem to generate two sequences, the first is something like this:

['ABCX9995', 'ABCX9996', 'ABCX9997', 'ABCX9998', 'ABCX9999', 'ABCY0001', 'ABCY0002']

The last part(number sequence) start at 0001 and go until 9999, when it reaches 9999 the letter changes and it should come back to 0001

I've already tried:
'ABC[XY][0-9]{4}'
'ABC[XY][0001-9999]{4}'

The other problem that I'm trying to solve is the start of the sequence, suppose that I have the same sequence above and I want to start it at ABCY1500, Is that possible?

@vwyu
Copy link
Contributor

vwyu commented Jan 30, 2020

It looks like 'ABC[XY](000[1-9]|00[1-9][0-9]|0[1-9][0-9]{2}|[1-9][0-9]{3})' solves your first problem.

For your second problem, regex-only solution may be too complicated. Instead, you can try

import exrex

str_list = list(exrex.generate('ABC[XY](000[1-9]|00[1-9][0-9]|0[1-9][0-9]{2}|[1-9][0-9]{3})'))
start = 1500
shift = 9998 + start
new_list = str_list[shift:] + str_list[:shift]
print(new_list)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants