Regular Expressions in Python Using The re Module

What is Regex?

Regex, or a more known terminology, Regular Expressions, is used to create complex patterns for searching substring inside Strings.

We have other methods of finding substring as well, but regex can cope up with way more complicated patterns than just normal searching for a substring.

How to Send Conditional Emails Based on Google Form Answers

The premium version of the Google Forms Email add-on allow you to set up notification emails that only trigger when one or more conditions are met.

For instance, if you have a Google Form that asks the age of the submitter, you can choose to send a notification to the parent if the age entered is less than 18. If you are using Google Forms for tech support, you can choose to send an email notification to the manager if the customer has picked “high” for the severity level.

Conditional or rule-based notifications in Google Forms can also be used to send an email notification to different people based on answers. For instance, you can set the notifications to go to apple@example.com only if the user has put iPhone or iPad in the product list.

Set up Notification Emails Based on Conditions

In this tutorial, we’ll explain how to set up notification emails that are trigger based on the form response. We would like the notifications to go out if the entered country is India OR if the email address contains ctrlq.org.

google-forms-conditional-emails.gif

Open the Google Form, go to Add-ons > Email Notifications for Forms > Create a new Email Notification. In the Specify Condition screen, choose “Match Any (OR)” since we need to trigger then email when either of the conditions is met.

Next choose “Country” in the “Select Field” drop-down, set the match type as “Equals” and the matching value as India. Similarly, add a condition for “Email Address” and set the match type as “Contains” as shown below.

Save the rule. If either of the conditions is met, the notifications are sent and the form entry is saved. If the conditions are not met, the notification email is skipped while the submitted data is still saved in your form.

Advanced Filters in Google Forms

The Google Forms add-on lets you easily create advanced filters with multiple criteria. Here are some examples.

form-test-conditions.png

For Text Fields

  • Equals - Answer exactly matches the specified text
  • Contains - Text is anywhere inside the answer field
  • Does not contain - Answer does not contain the specified text
  • Any of - Specify a list of values (comma separated) and the answer should be one of these values
  • None of - Answer should not equal to any item in the list (comma separated)
  • Is Empty - The answer is blank
  • Is Not Empty - The answer contains at least one character (not blank)

For Numeric Fields

  • Equal to - Answer matches the specified numeric value
  • Not Equal to - Answer doesn’t match the number
  • Greater than - Answer is greater or equal to number
  • Less than - Answer is less or equal to number

Tip: If you would like to check if an answer is between two numbers, create two conditions for the same field - greater than the lower limit and lower than the upper limit.

Regular Expressions

Advanced users may apply regular expressions to match answers against patterns. For instance, if you would like to send email notifications only when the city field contains exactly 4 characters, the regex value would be ^.{4}$ (case insensitive by default). A regex like (iPad|iPhone|Mac|Macbook) would match any Apple product.

Match all conditions or any

match-conditions.png

When setting up conditional notifications in Google Forms, you can also specify if the emails should be triggered only when all conditions are met or when either of the conditions is true.

Choose “Match any” for OR or “Match all” for AND (evaluate all conditions).