How to determine if a string other than English is in uppercase?

I use the following code to check for a string where all characters are uppercase:

if (preg_match('/^[\p{Lu}]+$/', $word)) { 

This works great in English, but it is not possible to detect letters with accents, Russian letters, etc. Is \ p {Lu} supposed to work in all languages? Is there a better approach?

+6
source share
2 answers

A special option is / u, which turns on Unicode negotiation mode instead of the default 8-bit negotiation mode. You must specify / u for regular expressions that use \ x {FFFF}, \ X, or \ p {L} to match Unicode characters, graphs, properties, or scripts. PHP will interpret '/ regex / u' as a UTF-8 string, not an ASCII string.

http://www.regular-expressions.info/php.html -

+6
source

using the u function, you can change the uppercase String .... The function is available here: string name = "manish niitian"; console.Writeline ("Your string is in upper case:" + name.UPPERCASE ());

0
source

Source: https://habr.com/ru/post/886421/


All Articles