python-perl
python-perl copied to clipboard
$1 after s/// not working
Hello,
would be great if your module would be able to do get the grouped characters from a substitution regex like this perl script does:
#!/usr/bin/perl
$sentence = "This is whatever.";
$sentence =~ s/([\.,:;]$)//;
$remove_punctuation_mark = $1;
print "<$sentence><$remove_punctuation_mark>\n";
I didn't find any way to do this with the normal python regex. With your perl module I would expect this to work:
#!/usr/bin/python3.8 -mperl
sentence = "This is whatever."
sentence =~ s/([\.,:;])$//
remove_punctuation_mark = $1
print(t, remove_punctuation_mark)
But this gives 2 errors:
-
Error:
sentence =~ s/([\.,:;])$// ^ SyntaxError: unexpected character after line continuation character -
If the regex is changed to e.g. s/([.,:;])$/X/ it throws the error: NameError: name '__perl__var__1' is not defined