It was narrated from Anas bin Malik that the Messenger of Allah (ﷺ) said:
"Seeking knowledge is a duty upon every Muslim, and he who imparts knowledge to those who do not deserve it, is like one who puts a necklace of jewels, pearls and gold around the neck of swines." (AR)
English reference (AR): Vol. 1, Book 1, Hadith 224 (AR)
Arabic reference (AR): Book 1, Hadith 229 (AR)