Is there a way in Python to do an if re match & group capture in the same line?
In PERL I would do it like this:
my $line = "abcdef";
if ($line =~ m/ab(.*)ef/) {
print "$1\n";
}
output:
badger@pi0: scripts $ ./match.py
cd
but the closest way I can find in Python is like this:
import re
line = 'abcdef'
if re.search('ab.*ef', line):
match = re.findall('ab(.*)ef', line)
print(match[0])
output:
badger@pi0: scripts $ ./match.pl
cd
which would seem to have to do the match twice.