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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -