Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Regex Rookie solution in Clear category for Stressful Subject by Selindian
import re
def is_stressful(subj):
"""
recognize stressful subject
"""
if subj.isupper(): return True # All in uppercase
if subj.endswith('!!!'): return True # Ends with three exclamation marks
subj = re.sub('[^a-z]+', '', subj.lower()) # Remove non a-z chars and lower text.
subj = re.sub(r'([a-z])\1+', r'\1', subj) # Reduce chars followed by the same char to one.
if re.search("(help|asap|urgent)", subj) != None: return True # includes help, asap or urgent
return False # Subject seems Ok.
if __name__ == '__main__':
#These "asserts" are only for self-checking and not necessarily for auto-testing
assert is_stressful("Hi") == False, "First"
assert is_stressful("I neeed HELP") == True, "Second"
print('Done! Go Check it!')
March 5, 2022