简体   繁体   中英

How to determine if a non-English string is in upper case?

I'm using the following code to check for a string where all the characters are upper-case letters:

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

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

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

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

using function u can do change in Uppercase of String .... Function Available here : string name="manish niitian"; console.Writeline("Your String in Uppercase is : "+name.UPPERCASE());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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