I would like to have a regular expression that checks if a string contains only upper and lowercase letters, numbers, and underscores.
I believe you are not taking Latin and Unicode characters in your matches. For example, if you need to take "ã" or "ü" chars, the use of "\w" won't work.
You can, alternatively, use this approach:
^[A-ZÀ-Ýa-zà-ý0-9_]+$
Hope it helps!