Simplify how substituting values works

The original purpose of this PR was to add a test for AnyValues filters, but it got a bit out of hand fixing the existing code.
Yep. I thought I had added a test case, but it seems I didn't, will do.