JSFiddle - React, Tailwind, and code Playground

HTML

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/3.5.4/select2.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/3.5.4/select2.js"></script>
<select class='select2'>
    <option>Select</option>
    <optgroup label="Vegetables">
        <option>Dr. R. N. Pandey</option>
        <option>Green R. P Pepper</option>
        <option>Kale</option>
    </optgroup>
    <optgroup label="Fruits">
        <option>Apple</option>
        <option>Orange</option>
        <option>Banana</option>
    </optgroup>
    <optgroup label="Nuts" disabled>
        <option>Almond</option>
        <option>Walnut</option>
        <option>Pine</option>
    </optgroup>
</select>

CSS

.select2 {
    width: 150px;
}

JavaScript

(function() {
    function matcher(term, text) {
      
        term = term.toUpperCase();
        text = text.toUpperCase().replace(/\./g, '').replace(/\s+/g, '');
        
        console.log(text);
        
        if (text.indexOf(term) > -1 ) {
            return true;
        }

        return false;
    }

    $(".select2").select2({
        matcher: matcher
    });
})();