fork download
  1. import re
  2. pattern = r'(?<!\S)(?:[^\so]*o){0,2}[^o\s]*(?!\S)'
  3. text = "hop hoop hooop hoooop hooooop"
  4. print(re.findall(pattern, text))
  5. print([x for x in text.split() if x.count("o") < 3])
Success #stdin #stdout 0.02s 9676KB
stdin
Standard input is empty
stdout
['hop', 'hoop']
['hop', 'hoop']