Consult a lawyer. I am not a lawyer. Your company is not you lawyer - they will give you advice that favors them. A lot will depend on the employment contract.
Typically the company will assert ownership of anything created on company time or using company resources. Copy paste is not legal if what you copy was produced on company time. That said if the code does not have other legal protection (e.g. patent) then just create it from scratch. They can't take away you know how to do it.
Some employment contracts may be so restrictive as to any (even on your time) software (or product) created during employment is company property. Like for a university professor this is common. Still if you wrote a generic snippet they cannot restrict you from recreating that - well they can try but I doubt it would stand up in court.
Code you copied from an outside open resource (like SE) is clearly not protected.
This is an example on legal advice. I was doing billable work on customer site. A person also on customer site was laid off. The contract was cancel-able and the customer just said fine we will cancel the contract with your (former) company and contract you directly. The (former) company told him he would be sued under the non-compete clause of his employment contact. He talked to HIS lawyer and the non-compete is void on a lay off. His lawyer talked to (former) company and threat of a law suit was immediately dropped and they told him they could not restrict him for working directly. Don't piss off your company for no good reason but also don't get legal advice from your company.