Jan-18-2020, 02:19 PM
(This post was last modified: Jan-18-2020, 02:19 PM by guraknugen.)
Hi!
I'm running Python3 in Manjaro Linux 18.1.5 and I want to ”emulate” sed. Here's an example in Bash using sed, this is the result I want:
What am I doing wrong that makes ”LibreOffice” appear at the end of the result? I'm obviously missing something here…
I'm running Python3 in Manjaro Linux 18.1.5 and I want to ”emulate” sed. Here's an example in Bash using sed, this is the result I want:
Output:~ $ echo "libreoffice-still 6.2.8-4" | sed -r 's/[^0-9]*([0-9\.\-]*)/LibreOffice \1/'
LibreOffice 6.2.8-4
I thought this would work in Python, but obviously it doesn't:import subprocess, re print(re.sub('[^0-9]*([0-9\.\-]*)', r'LibreOffice \1', "libreoffice-still 6.2.8-4"))
Output:LibreOffice 6.2.8-4LibreOffice
As you can see I used the exact same regular expressions, but the result is different and I don't understand why and what to do about it.What am I doing wrong that makes ”LibreOffice” appear at the end of the result? I'm obviously missing something here…