Check out the 4.13 development branch. This is a new feature so it would go in the next feature release anyway, and as part of my 4.13 work I fixed a number of inconsistencies exposed by the addition of type hints. In particular, the SoupStrainer API was rationalized. It's been a while so I don't remember the details, but I believe you should be able to put all of the logic for this into the _matches() method.
Check out the 4.13 development branch. This is a new feature so it would go in the next feature release anyway, and as part of my 4.13 work I fixed a number of inconsistencies exposed by the addition of type hints. In particular, the SoupStrainer API was rationalized. It's been a while so I don't remember the details, but I believe you should be able to put all of the logic for this into the _matches() method.