fork(1) download
  1. import re
  2. text = """Goiânia Vitória Brasília [Campo Grande] Fortaleza [São Paulo] Manaus [Santa Bárbara d'Oeste]"""
  3. regex = re.compile('\[(.*?)\]|(\S+)')
  4. matches = regex.finditer(text)
  5. for match in matches:
  6. if(match.group(1) is None):
  7. print(match.group(2))
  8. else:
  9. print(match.group(1))
Success #stdin #stdout 0.02s 9492KB
stdin
Standard input is empty
stdout
Goiânia
Vitória
Brasília
Campo Grande
Fortaleza
São Paulo
Manaus
Santa Bárbara d'Oeste