Indeed a difficult one if you don’t want to risk sticking with a match that cuts the song title apart. Since regex by default is greedy, trying to match very generic regex first against the music library, then, if nothing was found, trying the more specific regex with song and artist separation, probably is safest.
Otherwise it makes sense to be strict:
((the song (?P<title>.+)|something)( from the artist (?P<artist>.+))?|the artist (?P<artist>.+))
- the song abc
- the song abc from the artist xyz
- If playing a random song from an artist is allowed, playing any random song probably as well?
- something from the artist xyz
- the artist xyz
- Short from of
4., so it could be removed, but matches the example you gave.
The shorter/easier the signal words and the more alternatives you allow for those, like
artist/group/band, the more false matches occur, so either multiple regex need to be looped through to not match wrong or miss a match in the music library, or one has to live with either missing results (when full matches are allowed only) or a large number of results (when a title/artist only needs to contain the string matched by the regex), when a song title or artist name contains one or more of those signal words.