0

I have an svg with lines like this:

I want to remove the M's where the numbers after the M match the numbers after the L in front of it. I have this regex which seems to be working: https://regex101.com/r/UG2VHo/6

However when I try to remove all these instances using python's regex module, the printed string still includes those matching Ms.

import regex

with open('test-mjlr.svg','r') as svg:
    data = svg.read()
    r = regex.sub('L([0-9]+,[0-9]+) \KM\1','',data,flags = regex.M)
print r

How can I do this?

BigBoy1337
  • 4,735
  • 16
  • 70
  • 138
  • I can't get the \K to work with Python. Also I have seen that \K is supported in the regex model? https://stackoverflow.com/questions/39664058/is-there-any-equivalent-to-the-perl-regexes-k-backslash-sequence-in-python – BigBoy1337 Mar 23 '18 at 22:30
  • You are using the PyPi regex module, right? Then, the dupe is correct, you need to use a raw string literal. See http://rextester.com/ADXNYX34774 – Wiktor Stribiżew Mar 23 '18 at 22:36
  • It seems \K means literal 'K' in python regex. https://regex101.com/r/UG2VHo/7 – Thm Lee Mar 23 '18 at 23:55
  • You may try this regex for the same effect. 'L(\d*,\d*)\b M\1' and replace the match with 'L\1' https://regex101.com/r/UG2VHo/8 – Thm Lee Mar 24 '18 at 00:26

0 Answers0