Extract words from string with preg_match_all

前端 未结 7 2142
你的背包
你的背包 2020-12-21 17:14

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

相关标签:
7条回答
  • 2020-12-21 18:10

    When you use the u modifier, you can use the following pattern (demo):

    preg_match_all('(\w{4,})u', $string, $matches);
    print_r($matches[0]);
    

    The u modifier means:

    u (PCRE_UTF8): This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP 4.3.5.

    0 讨论(0)
提交回复
热议问题