Find lower/upper case letters in QGIS

If the string should contain lowercase, use this expression in 'Expression Dialog'

if(regexp_match("test",'([a-zäöüß]+)'),1,0)

for uppercase change '([a-zäöüß]+)' into '([A-ZÄÖÜ]+)'.

example1

Otherwise, I would recommend writing a small script as was suggested by @MortenSickel.

Personally for me it does not make sense writing a statement if(regexp_match(upper("test"),'([a-z]+)'),1,0) because it will always return 1 or 0 no matter what does your initial string look like.

To get the precise number of lower or upper characters in a string you can use the following code from the 'Function Editor'

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def upplow(field, feature, parent):
    upper, lower = [], []
    field_as_list = list(field)
    for i in field_as_list:
        if i.islower():
            lower.append(i)
        elif i.isupper():
            upper.append(i)
        else:
            continue
    return ('Lower: ' + str(len(lower)) + ', Upper: ' + str(len(upper)))

example2


References:

  • Regular Expressions — The Last Guide
  • Regex to match only uppercase “words” with some exceptions

I am pretty sure you would need to do this as a custom function. That makes it more of a general Python question than a GIS question, so it may be better to ask it at Stack Overflow.

But what I would do is to convert the string to upper (or lower) and then go through it letter for letter and take action as needed based on if the letter in my original string equals the corresponding letter in my uppered (or lowered) string.

for (initial, uppered) in zip(mystring, mystring.upper()):
   if initial==uppered:
      # Handle upper case
   else:
      # Handle lower case