Python use regex match object in if statement and then access capture groups like Perl
问题 Is it possible to do something like the following Perl code in Python? From what I can tell the answer is no, but I figured I'd double check. The Perl code I want to replicate in Python: #!/usr/bin/perl my $line = "hello1234world"; if($line=~/hello(.*)world/) { print($1); } #prints 1234 The following is the closest stylistically I can think off, but when running I (obviously) get the following error: import re line = "hello1234world" if matchObj = re.match(r'hello(.*)world',line): print