I have a string who did DID what ? what can I add to the below regex expression to search only if DID is in capital letters ?
output = re.findall(
r"did", # not adding DID here as the output maycome with did or DID but i need to check only when its all caps
searchstring,
)
>Solution :
You can find all CAPS letter word this way:
import re
txt = "who did DID what Did DiD?"
result = re.findall(r"\b[A-Z]+\b", txt)
print(result)
Output:
['DID']