1
I have a string with several words inside, some words are separated by space, but some are compound words and are protected by square brackets.
EX:
string = "Goiânia Vitória Brasília [Campo Grande] Fortaleza [São Paulo] Manaus"
I need to separate these words by returning a list of them separately.
EX OUTPUT:
"Goiânia"
"Victory"
"Brasilia"
"Campo Grande"
"Fortress"
"São Paulo"
"Manaus"
How do I create a regular expression that does this in python?
William, attentive to places where the apostrophe is part of the denomination. For example, Santa Bárbara d'Oeste.
– José Diz
William, since you edited the question, why don’t you take advantage and answer José’s comment about cities with compound names and an apostrophe? What should happen in this case, because you would have something like
"'Santa Bárbara d'Oeste'"
? Wouldn’t it be interesting to get the full name of the city? This quote in the name would be treated in some way?– Woss
Thanks José and Anderson, I think the ideal would be to change instead of using apostrophe it would be good to define as word delimiter compound keys or brackets, getting something like this. EX: string="Goiânia Vitória Brasília [Campo Grande] Fortaleza [São Paulo] Manaus". I will update the question!
– William Pereira de Paula
I added
[Santa Bárbara d'Oeste]
in the case of the answer, see if this regex helps you\[(.*?)\]|(\S+)
– brow-joe