JackBixuis
JackBixuis

Reputation: 35

Converting a simple regex line from perl to python

I am trying to convert this line from Perl to python:

$line =~ s/$alwayssep/ $& /g;

Any ideas how this might be done in python?

Upvotes: 0

Views: 94

Answers (2)

snoopyjc
snoopyjc

Reputation: 623

My Pythonizer converts that to this:

line = re.sub(re.compile(alwayssep),r' \g<0> ',line,count=0)

Upvotes: 1

Malik Brahimi
Malik Brahimi

Reputation: 16711

In Python, do the following where alwayssep is the expression and line is the passed string:

line = re.sub(alwayssep, r' \g<0> ', line)

Upvotes: 3

Related Questions