[英]PHP Regex find all capitalize words in string
PHP Regex find all capitalize words in string: PHP Regex在字符串中查找所有大写单词:
$string = "test sample test: 2015. ŽYDRŪNAS PAVARDENIS";
preg_match_all('/\b([A-Z-][\p{L}\pL]+)\b/', $string, $matches);
var_dump($matches);
Output: 输出:
array(2) {
[0]=>
array(2) {
[0]=>
string(8) "YDRŪNAS"
[1]=>
string(10) "PAVARDENIS"
}
[1]=>
array(2) {
[0]=>
string(8) "YDRŪNAS"
[1]=>
string(10) "PAVARDENIS"
}
}
Question is where disapear symbol ' Ž
' ? 问题是消失符号'
Ž
'?
HOw to modify regex
expresion, that will be not removed UTF-8
symbols ? 请问修改
regex
,即不会删除UTF-8
符号?
Basically you need to use the modifier u
option when working with unicode strings. 在使用unicode字符串时,您基本上需要使用修饰符
u
选项。 However the regex can also get simplified using the :upper:
character class because it will match all uppercased unicode characters. 但是,使用
:upper:
字符类也可以简化正则表达式,因为它将匹配所有大写的unicode字符。
Like this: 像这样:
$string = "test sample test: 2015. ŽYDRŪNAS PAVARDENIS";
preg_match_all("/[[:upper:]]+/u", $string, $matches);
var_dump($matches);
Output: 输出:
array(1) {
[0]=>
array(2) {
[0]=>
string(10) "ŽYDRŪNAS"
[1]=>
string(10) "PAVARDENIS"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.