1
Well I have a variable that receives a string, with the name of the city and can happen to have the neighborhood within parentheses. I need you to separate that into two variables.
Example 1:
$cidade = "BOA ESPERANÇA";
Return I need.
$nome_cidade = "BOA ESPERANÇA";
$bairro = null;
Example 2:
$cidade = "BOA ESPERANÇA (CENTRO)";
Return I need.
$nome_cidade = "BOA ESPERANÇA";
$bairro = "CENTRO";
How can I do that?
Regular expression is a solution.
– Woss
I believe that more information is missing in the question Hugo, what are the possible variations of the name of the city? will always be the name followed by the center between parentheses?
– RFL
And if only open parenthesis, but not close it, should be considered as neighborhood, as in
"BOA ESPERANÇA (CENTRO"
?– Woss
First of all you need to find the regular pattern in all occurrences, because any solution that appears will only serve for the examples presented, which apparently does not represent the problem as a whole.
– MagicHat
@RFL the neighborhood will always come within parentheses, however it may occur not to come the neighborhood soon will not have the parentheses
– Hugo Borges