seems like a crazy question but why not
>>> myval="ObjectId("5a60a394ac73c233ba1acc55")"
>>> myval.split("(")[1]
'"5a60a394ac73c233ba1acc55")'
>>> myval.split("(")[1].split(")")[0]
'"5a60a394ac73c233ba1acc55"'
>>> import re
>>> re.findall('[a-zA-z0-9]', myval.split("(")[1].split(")")[0])
['5', 'a', '6', '0', 'a', '3', '9', '4', 'a', 'c', '7', '3', 'c', '2', '3', '3', 'b', 'a', '1', 'a', 'c', 'c', '5', '5']
>>> "".join(re.findall('[a-zA-z0-9]', myval.split("(")[1].split(")")[0]))
'5a60a394ac73c233ba1acc55'
solved How to extract string using RE in python?