Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the regex for searching a word only if it is in All Capital letter?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading