Note: CC me I just read on lwn about the implementation of `%[` in sscanf. Just wanted to point out my implementation (which supports `]` ranges (`-`) and negation (`^`)) and let you know that you are free to take code/inspiration from it:
https://github.com/ShabbyX/kio/blob/master/src/scanf.c#L398