The role of government regulations in this regard is to prevent people who are not involved in the economic transaction from having to bear the costs caused by the externalities.
Water pollution would be one example of an externality. If the taxpayers as a group have to pay to clean up the water that a firm has polluted, they will bear the costs of this externality. In order to prevent this, the government regulates industries. It tells them that they may not pollute the water. This prevents the externality from happening and relieves the taxpayers of the need to pay for the costs associated with that externality.