import repunct = re.compile("[,\"\.!\?':;\-]")s = "This is why the Raspberry Pi Foundation loves their community translators. If you want to help out so there are no weird machine-translated videos, head here:"print(re.sub(punct," ", s)) # (regular expression, the replace, string)This is why the Raspberry Pi Foundation loves their community translators If you want to help out so there are no weird machine translated videos head here
import redef regex(string): """This function returns at least one matching digit.""" pattern = re.compile(r"\d{1,}") # For brevity, this is the same as r"\d+" result = pattern.match(string) if result: return result.group() return None# Call our function, passing in our stringprint(regex("007 James Bond"))007
import reline = "dance more dog"result = re.match(r"[^\d+]", line)print(result.group(0))d