In my date time value I want to use regex to strip out the slash and colon from time and replace it with underscore
Just format the datetime using strftime()
into the desired format:
>>> datetime.datetime.now().strftime("%m_%d_%y%H_%M_%S")'05_20_1517_20_16'
Another simple option is just using string replace :
s = "your time string"s = s.replace("/", "_").replace(":", "_")
Two ways:
i) use strftime with the format:
strftime("%m_%d_%y_%H_%M_%S")
ii) simply use replace() method of strings to replace '/' and ':' to '_'