I would like to generate string
matching my regexes using Python 3. For this I am using handy library called href="https://bitbucket.org/leapfrogdevelopment/rstr/" rel="nofollow
noreferrer">rstr.
^[abc]+.
[a-z]+
I
must find a generic way, how to create string that would match both my
regexes.
Modify
both regexes or join them in any way. This I consider as ineffective solution,
especially in the case if incompatible
regexes:
import
re
import rstr
regex1 =
re.compile(r'^[abc]+.')
regex2 =
re.compile(r'[a-z]+')
for index in range(0,
1000):
generated_string = rstr.xeger(regex1)
if
re.fullmatch(regex2, generated_string):
break;
else:
raise Exception('Regexes are probably
incompatibile.')
print('String matching both regexes is:
{}'.format(generated_string))
Is
there any workaround or any magical library that can handle this? Any insights
appreciated.
Asker
already has the string, which he just want to check against
multiple regexes in the most elegant way. In my case we need to
generate string in a smart way that would match
regexes.
No comments:
Post a Comment