Regular expression that match letters from all language php

前端 未结 1 617
广开言路
广开言路 2021-01-24 09:37

im trying for few hours to find the right regular expression in php to match any language letters but to prevent it to allow space

i have try this

[^\\p         


        
相关标签:
1条回答
  • 2021-01-24 09:47

    You need to specify the Unicode modifier u to get Unicode character properties in PCRE.

    For example...

    $pattern = "/([\p{L}]+)/u";
    $string  = "你好,世界!Привет мир! !مرحبا بالعالم";
    if (preg_match_all($pattern, $string, $match)) {
        var_dump($match);
    }
    

    Gives us...

    array(2) {
      [0]=>
      array(6) {
        [0]=>
        string(6) "你好"
        [1]=>
        string(6) "世界"
        [2]=>
        string(12) "Привет"
        [3]=>
        string(6) "мир"
        [4]=>
        string(10) "مرحبا"
        [5]=>
        string(14) "بالعالم"
      }
      [1]=>
      array(6) {
        [0]=>
        string(6) "你好"
        [1]=>
        string(6) "世界"
        [2]=>
        string(12) "Привет"
        [3]=>
        string(6) "мир"
        [4]=>
        string(10) "مرحبا"
        [5]=>
        string(14) "بالعالم"
      }
    }
    
    0 讨论(0)
提交回复
热议问题