How do I extract the address from a scriptPubKey?
Yes, to get addresses from scriptPubKeys, you will need to do a pattern match. There are only a small number of address types each with their own fixed scriptPubKey pattern. Keep in mind that not all scriptPubKeys map to an address so you will find scriptPubKeys that have no address and you will need to handle those.

Bitcoin Core has a pattern matcher for going from scriptPubKeys to address types in the solver function. The MatchPayToPubkey, MatchPayToPubkeyHash, and MatchMultisig can be found higher up in that file. The IsPayToScriptHash and IsWitnessProgram functions can be found here.

One thing to note about the solver is that it does not return just address types. Some of the types it returns do not map to addresses. These are TX_NULLDATA, TX_MULTISIG, TX_PUBKEY, and TX_NONSTANDARD.

It may also be useful for you to see how you get the scriptPubKey from an address. Bitcoin Core does it here.