Python Forum

Full Version: How to assign a found regex expression to a variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When I try to assign the regex expression I search for to a variable, I get this:

Quote:>>> studentnrRegex = re.compile(r'(18\d\d\d\d\d\d\d\d)')
>>> studentnr = studentnrRegex.search(text)
>>> studentnr
<_sre.SRE_Match object; span=(2071, 2081), match='1825010243'>

I thought I could just get the student number directly. Not so it seems.

What is the best way to get the actual student number, in this case 1825010243 out of there as a variable?
studentnr.group()
Thank you, that was what I needed!