aphp/dsfaker

generator regexp

parisni opened this issue · 4 comments

Hi @Dubrzr,

What about being able to generate string from regexp ?

eg:
y = GeneratorRegex("(0|\+33|0033)[1-9][0-9]{8}")
y.get_single()
-> +33166666666

Would be useful for my use cases
maybe some insight there:
http://stackoverflow.com/questions/274011/random-text-generator-based-on-regex

Anyway good job,

Thanks !

I've been looking at options for this, I've found https://github.com/asciimoo/exrex but it doesn't seem to be maintained a lot, python3.6 is not compatible...

In your link there is someone linking to http://www.cosc.canterbury.ac.nz/research/reports/TechReps/1997/tr_9710.pdf, maybe we could implement that but it may take some time.

Finally I've found https://bitbucket.org/leapfrogdevelopment/rstr/, and it works with your example:

import rstr
>>> rstr.xeger(r'[A-Z]\d[A-Z] \d[A-Z]\d')
'E1P 2I0'
>>> rstr.xeger(r'[A-Z]\d[A-Z] \d[A-Z]\d')
'M0S 1T0'
>>> rstr.xeger(r'[A-Z]\d[A-Z] \d[A-Z]\d')
'L9A 9L5'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'0834673019'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'0033470369802'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'0033917215395'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'0696840616'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'0033137496030'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'+33329135952'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'0033962572083'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'0033152760196'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'0033776704265'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'0289786407'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'+33871072490'
>>> rstr.xeger(r'(0|\+33|0033)[1-9][0-9]{8}')
'0562550999'

So i'll maybe go with rstr at first and if a got some time one day i'll look at implementing the paper.

Fantastic !
Before I implement the paper myself,
I can't wait for the 0.2 version of dsfaker available on pip

I'll add it asap!

0.2 available on pypi ;)