Deterministic discrimination of nonorthogonal states is forbidden by quantum measurement theory. However, if we do not want to succeed all the time, i.e., allow for inconclusive outcomes to occur, then unambiguous discrimination becomes possible with a certain probability of success. A variant of the problem is set discrimination: the states are grouped in sets and we want to determine to which particular set a given pure input state belongs. We consider here the simplest case, termed quantum state filtering, when the N given nonorthogonal states {\psi(1)>,...,\psi(N)>} are divided into two sets and the first set consists of one state only while the second consists of all of the remaining states. We present the derivation of the optimal measurement strategy, in terms of a generalized measurement (positive-operator-valued measure), to distinguish \psi(1)> from the set {\psi(2)>,...,\psi(N)>} and the corresponding optimal success and failure probabilities. The results, but not the complete derivation, were presented previously [Phys. Rev. Lett. 90, 25901 (2003)] as the emphasis there was on appplication of the results to probabilistic quantum algorithms. We also show that the problem is equivalent to the discrimination of a pure state and an arbitrary mixed state.