Regular expression to search for Gadaffi

后端 未结 15 1790
鱼传尺愫
鱼传尺愫 2020-12-07 07:05

I\'m trying to search for the word Gadaffi. What\'s the best regular expression to search for this?

My best attempt so far is:

\\b[KG]h?add?af?fi$\\         


        
15条回答
  •  一向
    一向 (楼主)
    2020-12-07 07:10

    One interesting thing to note from your list of potential spellings is that there's only 3 Soundex values for the contained list (if you ignore the outlier 'Kazzafi')

    G310, K310, Q310

    Now, there are false positives in there ('Godby' also is G310), but by combining the limited metaphone hits as well, you can eliminate them.

     1){
            $matches[] = $item;
        }
    }
    $pattern = implode("|",$matches);
    $text = preg_replace("/($pattern)/","$1",$text);
    echo $text;
    ?>
    

    A few tweaks, and lets say some cyrillic transliteration, and you'll have a fairly robust solution.

提交回复
热议问题