I have a display name field which I have to validate using Ruby regex. We have to match all language characters like French, Arabic, Chinese, German, Spanish in addition to English language characters except special characters like *()!@#$%^&…. I am stuck on how to match those non-Latin characters.
Share
There are two possibilities:
Create a regex with a negated character class containing every symbol you don’t want to match:
This solution may not be feasible, since there is a massive amount of symbols you’d have to insert, even if you were just to include the most common ones.
Use Oniguruma (see also: Oniguruma for Ruby main). This supports Unicode and their properties; in which case all letters can be matched using:
You can see what these are all about here: Unicode Regular Expressions