Jump to content

Python: Difference between revisions

Line 174: Line 174:
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
import re
import re
myReg = re.compile(r'height:(\d+)cm')
my_regex = re.compile(r'height:(\d+)cm')
myMatch = myReg.match("height:33cm");
my_match = myReg.match("height:33cm");
print(myMatch[1])
print(my_match[1])
# 33
# 33
</syntaxhighlight>
</syntaxhighlight>
;Notes
;Notes
* <code>re.match</code> will return None if there is no match
* <code>re.match</code> will return None if there is no match