I'm trying to create a regex in javascript that detects if the string contains any uppercase characters for all languages.
I've tried the modifier /u
but it doesn't work, I'm beginning to believe that this is not possible in a simple way.
I'm not interested in messing up the code with all the characters from all the languages.
const string01 = "ñ Ñ ç Ç";
const string02 = "ñ Ñ ç Ç A";
const regex = /[A-Z]/gu
console.log(regex.test(string01)) // false
console.log(regex.test(string02)) // true
The problem with your regex is that [AZ] does not include the letters that are not common in all Latin alphabets: the Ñ, the Ç, vowels with accents, umlauts or umlauts...
For each language you want to support you would have to extend this regular expression.
Another option would be to check whether each character is uppercase or not:
I think that in this particular case it is not very easy using regex, I think that a possible approach is to check each letter with the same letter
.toUpperCase()
and only compare letters of any language, removing everything else with/[^\p{L}]/gmu
:\p{L}
is used to match any letter of any language if used with the flagu
. All inside[^]
is for you to select everything except what is inside (any letter of any language).