Python generate string based on regex format -
i have difficulties learning regex
in python. want parse tornado web route configuration along arguments request path string without handlers request.path method. example, have route patterns like:
/entities/([0-9]+)
/product/([0-9]+/actions
the expected result combine integer parameter (123) string like:
/entities/123
/product/123/actions
how generate string based on pattern?
thank in advance!
this might possible duplicate to:
reversing regular expression in python
generate string matches regex in python
using answer provided @bjmc solution works this:
>>> import rstr >>> intermediate = rstr.xeger(\d+) >>> path = '/product/' + intermediate + '/actions'
depending on how long want intermediate integer, replace regex: \d{1,3}
Comments
Post a Comment