That's not exactly what it means though. It's more like "oh no!" - from dictionary.com:Near the end, Professor Dumbledore is trying a couple of Harry's Bertie Bott's Every Flavour Beans. He says, "Alas! Earwax!" Kind've like Finally! Earwax! as he hadn't had an earwax-flavored bean before.
As has been mentioned, it's pretty archaic/old-fashioned (which explains why it fits in fantasy literature like "Harry Potter").–interjection (used as an exclamation to express sorrow, grief, pity, concern, or apprehension of evil.)
I'm still not sure I agree. Sure, there is perhaps a pragmatical meaning between the lines along the lines of "at last I found the last flavour", but if you look at it purely semantically, he's expressing his misfortune with finding the (disgusting) ear wax.In that context, it could've been a combination of "finally" and "oh no" Dumbledore likes to find all flavors and I can't imagine earwax tasting so good.
Hamlet, Act V, Scene 1.This same skull,
sir, was Yorick's skull, the king's jester.
Alas, poor Yorick! I knew him, Horatio: a fellow
of infinite jest, of most excellent fancy: he hath
borne me on his back a thousand times; and now, how
abhorred in my imagination it is!