def build_whitespace_split_regex(text):
 def __build_parts(text):
  lexer = shlex.shlex(text)
  lexer.whitespace_split = True
  lexer.commenters = ''
  if ("'" in text):
   lexer.quotes = '"'
  elif ('"' in text):
   lexer.quotes = "'"
  return list(lexer)
 regex = ''
 for line in text.splitlines():
  parts = [re.escape(s) for s in __build_parts(line)]
  regex += '(?:[\\s]+)?{0}(?:[\\s]+)?'.format('(?:[\\s]+)?'.join(parts))
 return '(?m)^{0}$'.format(regex)

def build_whitespace_split_regex ( text ) : def __build_parts ( text ) : lexer = shlex . shlex ( text ) lexer . whitespace_split = True lexer . commenters = '' if ( "'" in text ) : lexer . quotes = '"' elif ( '"' in text ) : lexer . quotes = "'" return list ( lexer ) regex = '' for line in text . splitlines ( ) : parts = [ re . escape ( s ) for s in __build_parts ( line ) ] regex += '(?:[\\s]+)?{0}(?:[\\s]+)?' . format ( '(?:[\\s]+)?' . join ( parts ) ) return '(?m)^{0}$' . format ( regex )
create a regular expression at runtime which should match ignoring the addition or deletion of white space or line breaks .