Error in Python Regex? (re.sub with re.MULTILINE)

I notice some strange behavior in the Python Regex library, and I'm not sure if something is wrong.

If I run regex using re.sub() , with re.MULTILINE . It seems to only replace the first few cases. It replaces all occurrences if I disable re.MULTILINE , use re.subn(..., count = 0, flags = re.MULTILINE) or compile the regex with re.compile(..., re.MULTILINE) .

I am running Python 2.7 on Ubuntu 12.04.

I sent a random example:

  • Pastebin.com - terminal output
  • codepad - Script confirming the behavior (with the exception of re.subn (), which is different from 2.5)

Can someone confirm or deny this behavior on their machine?

EDIT: Implemented, I have to continue and publish it in Python. EDIT 2: Error Message: http://bugs.python.org/msg168909

+6
source share
1 answer

Using

 re.sub(pattern, replace, text, flags=re.MULTILINE) 

instead

 re.sub(pattern, replace, text, re.MULTILINE) 

which is equivalent

 re.sub(pattern, replace, text, count=re.MULTILINE) 

which is a mistake in your code.

See re.sub ()

+16
source

Source: https://habr.com/ru/post/923524/


All Articles