Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm not good with regex but i want to use it to extract words from a string.

The words i need should have minimum 4 characters and the provided string can be utf8.

Example string:

Sus azahares presentan gruesos pétalos blancos te?idos de rosa o violáceo en la parte externa, con numerosos estambres (20-40).

Desired output:

Array(
    [0] => azahares
    [1] => presentan
    [2] => gruesos
    [3] => pétalos
    [4] => blancos
    [5] => te?idos
    [6] => rosa
    [7] => violáceo
    [8] => parte
    [9] => externa
    [10] => numerosos
    [11] => estambres
)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
760 views
Welcome To Ask or Share your Answers For Others

1 Answer

This works if the words to look for are UTF-8 (at least 4 chars long, as per specs), consisting of alphabetic characters of ISO-8859-15 (which is fine for Spanish, but also for English, German, French, etc.):

$n_words = preg_match_all('/([a-zA-Z]|xC3[x80-x96x98-xB6xB8-xBF]|xC5[x92x93xA0xA1xB8xBDxBE]){4,}/', $str, $match_arr);
$word_arr = $match_arr[0];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...