Python regular expression substitute whitespace for hyphen
Question: I get a lob object that may have one or many dates. thinking of the dates as a
table if the first date is empty I get a chr(20). ex 3rd element of array has
a date the first two empty would look similar to " "," ","01/01/01 01:01:01".
I would like to change the " " in the date time string to something different
("-") so I can easily differentiate between just an empty element and an
actual date time value with a space in the middle. Brand new to python and
regular expressions would not be considered my strong suit.

    
    
    >>> x = '01/01/12 17:11:11'
    >>> y = re.sub( r"\d{2} \d{2}", r"\d{2}-\d{2}",x)
    >>> print (x,y)
    01/01/12 17:11:11 01/01/\d{2}-\d{2}:11:11
    


Answer: Use lookahead and lookbehind assertions:

    
    
    >>> import re
    ... x = '01/01/12 17:11:11 random junk 01/08/10 12:01:33'
    ... y = re.sub(r'(?<=\d{2}) (?=\d{2})', '-', x)
    ... y
    103: '01/01/12-17:11:11 random junk 01/08/10-12:01:33'
    

