كتاب الأيمان
27  
The Book of Oaths
(3)
Chapter: It is recommended for the one who swears an oath then sees that something else is better than it; To do that which is better and offer expiation for his oath
(3)
باب نَدْبِ مَنْ حَلَفَ يَمِينًا فَرَأَى غَيْرَهَا خَيْرًا مِنْهَا أَنْ يَأْتِيَ الَّذِي هُوَ خَيْرٌ وَيُكَفِّرَ عَنْ يَمِينِهِ
Sahih Muslim 1651 b

'Adi b. Hatim reported Allah's Messenger (ﷺ) as saying:

He who took an oath, but he found something else better than that, should do that which is better and break his oath.
وَحَدَّثَنَا عُبَيْدُ اللَّهِ بْنُ مُعَاذٍ، حَدَّثَنَا أَبِي، حَدَّثَنَا شُعْبَةُ، عَنْ عَبْدِ الْعَزِيزِ بْنِ رُفَيْعٍ، عَنْ تَمِيمِ بْنِ طَرَفَةَ، عَنْ عَدِيِّ بْنِ حَاتِمٍ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏ "‏ مَنْ حَلَفَ عَلَى يَمِينٍ فَرَأَى غَيْرَهَا خَيْرًا مِنْهَا فَلْيَأْتِ الَّذِي هُوَ خَيْرٌ وَلْيَتْرُكْ يَمِينَهُ ‏"‏ ‏.‏
Reference : Sahih Muslim 1651b
In-book reference : Book 27, Hadith 23
USC-MSA web (English) reference : Book 15, Hadith 4057
  (deprecated numbering scheme)