Regex to exclude emojis

488
2
Jump to solution
01-22-2024 12:14 PM
CoreyWilliamsESRIAccount
New Contributor II

I am running into an issue where users may enter emojis in my survey in a free text notes field.  This isn't an issue until I create a Survey123 Report. 

I am looking for help to create a regex formula which will allow regular words, numbers and punctuation but exclude emojis.  I have tried using Regex 101 and ChatGPT - the formulas pass in Regex 101 but fail in Survey123.

Here is the latest iteration: regex(.,"^[\p{L}\p{N}\p{P}\p{Zs}]+$").

Any help would be appreciated.

1 Solution

Accepted Solutions
abureaux
MVP Regular Contributor

I had a recent regex issue like this, and in my research I read some amazing advice that may be helpful in this case as well. It essentially boiled down to "it may be easier to make a regex expression for the characters you want to allow".

In my case, people were adding special characters to a field used for generating a file name (which is kind of an issue). At first, I wanted to exclude special characters... but that proved to be annoying. In the end, I settled for allowing only certain characters. E.g.,

regex(.,'^[a-zA-Z0-9\. _-]*$')

View solution in original post

2 Replies
abureaux
MVP Regular Contributor

I had a recent regex issue like this, and in my research I read some amazing advice that may be helpful in this case as well. It essentially boiled down to "it may be easier to make a regex expression for the characters you want to allow".

In my case, people were adding special characters to a field used for generating a file name (which is kind of an issue). At first, I wanted to exclude special characters... but that proved to be annoying. In the end, I settled for allowing only certain characters. E.g.,

regex(.,'^[a-zA-Z0-9\. _-]*$')

CoreyWilliamsESRIAccount
New Contributor II

Thanks!  This worked great.  Any idea how I can include both " and ' ?

I receive an error message in Survey123 Connect when trying to add an escape before either:
regex(.,'^[a-zA-Z0-9\. _-\'\"]*$')

0 Kudos