Catching different prefixes, remove part of them and search in database

Currently, it’s simple configuration. I have sip users saved in table sipfriends. The goal is on an incoming call to check if prefix exists. If exists - remove it and look into the table for that number.