def pretty_match(match, string, underline_char='^'):
 start = match.start()
 end = match.end()
 string = _LINE_RGX.sub(linesep, string)
 start_line_pos = string.rfind(linesep, 0, start)
 if (start_line_pos == (-1)):
  start_line_pos = 0
  result = []
 else:
  result = [string[:start_line_pos]]
  start_line_pos += len(linesep)
 offset = (start - start_line_pos)
 underline = ((' ' * offset) + (underline_char * (end - start)))
 end_line_pos = string.find(linesep, end)
 if (end_line_pos == (-1)):
  string = string[start_line_pos:]
  result.append(string)
  result.append(underline)
 else:
  end = string[(end_line_pos + len(linesep)):]
  string = string[start_line_pos:end_line_pos]
  result.append(string)
  result.append(underline)
  result.append(end)
 return linesep.join(result).rstrip()

def pretty_match ( match , string , underline_char = '^' ) : start = match . start ( ) end = match . end ( ) string = _LINE_RGX . sub ( linesep , string ) start_line_pos = string . rfind ( linesep , 0 , start ) if ( start_line_pos == ( - 1 ) ) : start_line_pos = 0 result = [ ] else : result = [ string [ : start_line_pos ] ] start_line_pos += len ( linesep ) offset = ( start - start_line_pos ) underline = ( ( ' ' * offset ) + ( underline_char * ( end - start ) ) ) end_line_pos = string . find ( linesep , end ) if ( end_line_pos == ( - 1 ) ) : string = string [ start_line_pos : ] result . append ( string ) result . append ( underline ) else : end = string [ ( end_line_pos + len ( linesep ) ) : ] string = string [ start_line_pos : end_line_pos ] result . append ( string ) result . append ( underline ) result . append ( end ) return linesep . join ( result ) . rstrip ( )
return a string with the match location underlined: .