简体   繁体   English

如何在PHP中将大写单词字符与正则表达式匹配?

[英]How to match uppercase word character with regex in PHP?

I know there is the [AZ] notation.. but I am not sure if [az] is the same as \\w .我知道有[AZ]符号..但我不确定[az]是否与\\w相同。

I'd like to match \\w , but only if it's uppercase.我想匹配\\w ,但前提是它是大写的。

This should include all the weird characters like Ę, Ą, Ś, Ć, Ź, Ż, Ś, Ł, Ó, Ń .这应该包括所有奇怪的字符,如Ę, Ą, Ś, Ć, Ź, Ż, Ś, Ł, Ó, Ń

You can use Unicode character properties .您可以使用Unicode 字符属性 For example,例如,

'/\p{Lu}/u'

Will match any uppercase letter.将匹配任何大写字母。

\\w is equivalent of this character class: \\w相当于这个字符类:

[a-zA-Z0-9_]

If you want upper case unicode characters only then use this character class:如果您只想要大写 unicode 字符,请使用此字符类:

'/[\p{Lu}\p{N}_]/u'

This will match any one of:这将匹配以下任何一项:

  1. Upper case unicode letter大写 Unicode 字母
  2. unicode number Unicode 号码
  3. Underscore下划线

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM