[Solved] How do I remove all strings containing digits before “hs” like “18hs” from a list of strings? [closed]
>>> import re >>> words = [“hello”, “18hs”, “18aaa”, “21hr”] >>> [w for w in words if not re.match(r’\d+h’, w)] [‘hello’, ’18aaa’] This loops over the list and keeps the items that don’t match the regex \d+h, which means “one or more digits followed by an h”. If you need to keep strings like 7hg, … Read more