Apply Regex

The Apply Regex building block allows you to perform advanced text formatting and manipulation using regular expressions.

Methods

  1. Replace text Replaces text matching the given regular expression with a replacement value.

    • Example 1: Replace the first occurrence of "birds" with "dogs": Input Text: "cats eat birds and birds fly" Regex: /birds/ Replacement: "dogs" Result: "cats eat dogs and birds fly"

    • Example 2: Replace all occurrences of "birds" with "dogs": Regex: /birds/g Result: "cats eat dogs and dogs fly"

  2. Extract matches Extracts text that matches the given regular expression.

    • Example 1: Extract the first match of "abc": Input Text: "abcabc" Regex: /abc/ Result: "abc"

    • Example 2: Extract all matches of "abc": Regex: /abc/g Result: ["abc", "abc"]

  3. Check if pattern matches Checks if the text contains a match for the given regular expression and returns true or false.

    • Example: Check if "abc" exists in "abc123": Regex: /abc/ Result: true

Flags

You can add flags to modify the behavior of your regular expressions.

Examples of typically used flags:

  • g: Global search (matches all occurrences).

  • i: Case-insensitive search.

  • m: Multiline search.

  • Example: /example/gi performs a global, case-insensitive search.

Use Case Example: Extract Google Sheet IDs

Imagine you have a list of Google Sheets links and need to extract the IDs.

  • Your building block set-up:

  • Result: Extracted ID is "1aBcD_12345_EfGhI67-JklMnOpqrstu890".

Additional Notes

  • If the input text is empty, the TaskBot will take no action and continue running.

  • If your regex is invalid, the TaskBot will generate an error report and stop run/loop.

  • You can validate and test your regex using tools like regex101.com.

FAQ

I'm not a developer, can I still use regex?

Absolutely! Regex is simply a sequence of characters that specifies a match pattern in text. Anyone can use it. There are many reference guides on the internet to learn more. Here is one example: Regex reference guide.

Last updated