Skip to content

$1 after s/// not working #3

@ruppde

Description

@ruppde

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:

  1. Error:
    sentence =~ s/([\.,:;])$// ^ SyntaxError: unexpected character after line continuation character

  2. If the regex is changed to e.g. s/([.,:;])$/X/ it throws the error: NameError: name '__perl__var__1' is not defined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions