Splitting texts in an array

How to get a separate array for movie names and years from the array?

l = [“The Wizard of Oz (1939)”, “Citizen Kane (1941)”, “The Cabinet of Dr. Caligari (Das Cabinet des Dr. Caligari) (1920)”, “Casablanca (1942)”]

desired results:

Movies = [“The Wizard of Oz”, “Citizen Kane”, "The Cabinet of Dr. Caligari (Das Cabinet des Dr. Caligari) ", “Casablanca”]

Years = [“1939”, “1941”, “1920”, “1942”]

Any help will be much appreciated.

Cheers.

Welcome!

I would use Regular expressions:
https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions

For your example this can do, if every string is behaving nice:

re=r"(.*)\s+\((.*)\)$"
m=match.(re,l)
julia> m[1].captures
2-element Array{Union{Nothing, SubString{String}},1}:
 "The Wizard of Oz"
 "1939"

julia> m[2].captures
2-element Array{Union{Nothing, SubString{String}},1}:
 "Citizen Kane"
 "1941"
3 Likes

Thank you.

1 Like