Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$1 after s/// not working #3

Open
ruppde opened this issue Feb 25, 2020 · 0 comments
Open

$1 after s/// not working #3

ruppde opened this issue Feb 25, 2020 · 0 comments

Comments

@ruppde
Copy link

ruppde commented Feb 25, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant