Take the 2-minute tour ×  I'm working on a Python project with
user input, and want to reuse specific parts (i.e the part/s
that have matched a regular expression) in the output, so a
dialog could go something like:  Program: Hello, what have you
been doing today? User: I have been foobaring./I went
foobaring./(anything else containing 'foobaring') [Where the
regular expression is '[a-zA-Z]*ing'] Program: Do you like
foobaring?  ..but would also have the same result no matter what
activity the user entered, so long as it ended in 'ing'.  I
currently use variables for the regular expression and the user
input like so:  variable = re.compile('regexp')   userinput =
raw_input()  so I can use them in an if later on.  TL;DR: Is
there anything that returns the string that is the portion of a
larger string that matches a regular expression  share|improve
this question add comment  1 Answer  If you surround the regex
with parentheses (to make it a group), then you can access that
group using match.group(1):  In [89]: