I want to get the first occurrence between two character if both exist, otherwise get what is before the first character found.
For example, on the strings below:
25 de Março - Centro Histórico de São Paulo, São Paulo - SP, Brasil
Centro Histórico de São Paulo, São Paulo - SP, Brasil
Rua Hamilton Prado, 398 - Chácara Belenzinho, São Paulo - SP, 03376-000, Brasil
I want to get what is behind the '-' character. However, the second string only has one '-', so I want to get everything that is behind it.
The results I am looking for are:
Centro Histórico de São Paulo, São Paulo
Centro Histórico de São Paulo, São Paulo
Chácara Belenzinho, São Paulo
I tried the following regex [^-\n]+(?=-[^\n-]*$) but it does not return what I want on the last string.
Is it possible to solve with regex?