How to match uppercase word character with regex in PHP?

前端 未结 2 714
甜味超标
甜味超标 2020-12-21 07:41

I know there is the [A-Z] notation.. but I am not sure if [a-z] is the same as \\w.

I\'d like to match \\w

相关标签:
2条回答
  • 2020-12-21 08:10

    \w is equivalent of this character class:

    [a-zA-Z0-9_]
    

    If you want upper case unicode characters only then use this character class:

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

    This will match any one of:

    1. Upper case unicode letter
    2. unicode number
    3. Underscore
    0 讨论(0)
  • 2020-12-21 08:18

    You can use Unicode character properties. For example,

    '/\p{Lu}/u'
    

    Will match any uppercase letter.

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