How do i fix my MacBook Pro 13 from malware attack?
Nothing you’ve described indicates malware...

On opening Safari it takes me to Yahoo...

Mine takes me to Bing. I have my home page and default search engine set to Bing, so this is normal. Check to see what yours are set to.

I have tried to clear extensions yet it doesn't work.

Which extensions? What doesn’t work, Safari or the extension?

Now I can't see any extensions under it's tab as well.

You just stated you tried to clear them out, if you did that, there won’t be any listed.
It’s very unlikely it’s malware.  If you are downloading and installing every piece of software you run into, then yes, you probably are infected in some way.
I personally use a Synology NAS with AV built into it.   As for AV, I actually don’t use on my &quot;production&quot; machine because I'm very, very particular about what gets installed.  However, with a new app, I will usually test it out on a VM with AV, or on an old “scrap” Mac and with APFS snapshots enabled. I take a snap before I make changes prior to installation.  If the application is malware, garbagewae, or spyware (i.e. a Font program that wants access to GPS and contacts) I roll back to a previous snapshot like it never happened.
Now, with all that said, there’s an AV company, I’ve got my eye on - PC Matic (yeah, those guys).  What I like is that they have a white/blacklist model.  If the app is not on the whitelist, it’s not going to run; even legit ones!  So, it really locks things down, but if you’re in a rush to do a  demo of some new software and have whitelisted it, you are up the proverbial creek.
Personally, I think  it might be a strong supplement to Gatekeeper; more testing needs to be done, though.