I'm trying to extract substrings from folder-names(music-album-names with release-year) with Erlang-regex. I don't expect it to work for all folder-names but if it works for 90% it would be good enough. I need the name of the album and the year of release. And if there is a year of remastering, I need that also. I basically want to exclude any special-characters such as -[]()
and strings such as "Remastered, Live, Recorded"
The cases, so far, I want to handle are:
1985-An Album Title %return: 1985 An Album Title
1985-An Album Title (2003 Remastered) %return: 1985 An Album Title 2003
An Album Title-1985 %return: An Album Title 1985
An Album Title 1985 %this should be returned as is
An Album Title % "
1984 % "
1985 An Album Title % "
My attempt first check for a correct year-format but then I'm stuck on the hyphen(-) after "1989". How can I ignore the hyphen or replace it with a blank space?
test_regex() ->
Str = "1989-Dr.Feelgood [2009, 2CD Deluxe Edition]",
RegEx = "(^(?:19|20)\\d{2})* <--- What next? %(?![-])D",
case re:run(Str, RegEx, [{capture, first, list}]) of
{match, Captured} -> io:format("Captured: ~p~n",[Captured]);
nomatch -> io:format("no match ~n")
end.
There is also a replace-function but I can't figure out how use it properly:
test_regex() ->
Str = "1989-Dr.Feelgood [2009, 2CD Deluxe Edition]",
RegEx = "(^(?:19|20)\\d{2})*-.*",
case re:replace(Str, RegEx, "\s", [{return, list}]) of
X -> io:format("X ~p ~n",[X])
end.
\s*\b(?:Remastered|Live|Recorded)\b|[^\da-zA-Z]
– Wiktor Stribiżew Apr 2 at 19:34