Python newbie here, using 3.5. I feel this question is similar to others asked here, but despite having read those and trying to follow the advice given, I'm still not getting anywhere with this regex.
I have a string of text wherein I want to replace, with a space, all newlines which are not followed by either another newline or three spaces. I'm attempting to do this using a regular expression with a negative lookahead. I've learned I need to use multiline from this conversation. Still, though, my regex isn't identifying anything in my string. Basically, I want to match and replace the \r\n in the middle of the string below, while leaving those at the beginning and end of the string untouched.
body = 'foo foo\r\n\xa0\xa0\xa0foo foo foo\r\n\foo foo foo foo foo\r\n\r\n\foo foo foo'
breakRegex = re.compile(r'(\r\n)?!(\r\n)|(\r\n)?!(\s\s\s)', s,re.M)
breakRegex.sub(' ', body)
The desired and so-far-unreached outcome would be:
'foo foo\r\n\xa0\xa0\xa0foo foo foo foo foo foo foo foo\r\n\r\n\foo foo foo'
I've also tried the above without so many parentheses, substituting \s for \xa0 and more, but it still doesn't work... Thanks for any help you can give.