Implement SSL MITM tool which can drop and pass the packets based on some rules and mark(iptables) the packet.
Iptables would queue or redirect the packet to your program. Packet would have a iptables mark. Now our program should filter content based on some regex rules which can be dynamically added.If it does not match, packet should be dropped else start the MITM connection with the mark specified above.
You have to do the progarmming in c language