import re


def clear_new_lines_and_strip_spaces(str):
    """
    replace new lines with single space.
    spaces before new line and after new line are contracted to single space.
    spaces striped on the begiging and the end of the string.
    Sample:
    'an   incredible  \n   text\n\n ' -> 'an   incredible text'
    """
    return re.sub(r'\s*\n\s*', ' ', str).strip()