What is "Regex"?
Regular expressions, better known as "regex", are used to search through a given body of text for specific terms.This is similar to the Ctrl-F search feature in a text editor such as Microsoft Word. Regarding auto responses, regex can be useful catch multiple responses that may mean the same thing. For example, a student can respond either ‘Yes’ or ‘yes’ to a given message. To a computer, these would be interpreted as different inputs. It would be ideal if we could have these process as the same response, so we add a regex to account for the differences.
Can you show me some examples?
Take the following sentence, “The quick fox jumps over the lazy brown dog.” To search the sentence for just the word ‘fox’ we would simply use the regex ‘fox’.
- “The quick fox jumps over the lazy brown dog.”
To search the sentence for both ‘The’ and ‘the’ we would use the regex ‘[tT]he’.
- “The quick fox jumps over the lazy brown dog.”
To search the sentence for every space we would use the regex ‘\s’.
- “The quick fox jumps over the lazy brown dog.”
Basic Metacharacters
Here are a few basic "metacharacters" that you can use in your regex that can give you some more flexibility. I'll list more examples below.
The period is our first example, ".". The period returns any character that is not a line break. Second, we have brackets, "[]". The brackets return any of the characters contained within. For example, ‘[ab]’ would return either ‘a’ or ‘b’. In addition, the brackets can be used as a range. So ‘[a-z]’ would return any lowercase letter of the alphabet. ‘[0-8]’ would return any digit except 9. Next, we have a slash going from top left to bottom right, "\". The backslash is a special character that will escape whatever predefined meaning the character may already have. For example, if we wished to match every period in a paragraph, we could not simply use ‘.’, that would return every non line break character. Instead we would use ‘\.’, which will return every period instead. Lastly, we have the pipe, "|". The pipe will return either what is before it or what is after it. For example ‘fox|lazy’ would match “The quick fox jumps over the lazy brown dog.”
Here's a pretty common example we've seen with several schools: using the auto response "apply". We have a campaign message that says “Please respond ‘apply’ to receive information about the application.” A student could respond with “apply”, “ apply”, “APPLY”, or even “ApPLY”, if they are feeling so delightfully inclined. We can use the following regex to catch all of these: ‘[aA][pP][pP][lL][yY]’. Breaking the regex down, we can see that for the first character, the regex will catch either ‘a’ or ‘A’ through the ‘[aA]’ portion of the regex. Each subsequent bracket group will catch either the uppercase or lowercase character that we would want. What’s important to note is that even for the response that is “ apply” (note the space in between the first quote and the letter a), this regex will catch it. This is because the regex searches the entire response for the searched for term, so the leading space character is passed over and just the ‘apply’ is matched from the end of the response.
Here is another example with screenshots from the platform.'The top auto response will only activate if the message received is exactly “money”. The second auto response will only activate if the message received is exactly “ money”. The third one, thanks to regex, will activate regardless of whether the response is “money” or “ money”.
I hope that helps get you started on using regex in your auto responses! If you have any questions, you can create a support ticket.
Comments
0 comments
Please sign in to leave a comment.