Using the Text Formatter Module
Overview
The Text Formatter module in FlowMattic allows users to perform advanced operations on textual content within their workflows. This article provides a detailed explanation of each available action, its use case, and examples to help you utilize the module effectively.
Available Actions and Use Cases
1. Extract Pattern
Use regular expressions to extract specific patterns or strings from the text.
- Example: Extract email addresses from a block of text using a regex pattern.
2. Find in Text
Search for specific text within the content.
- Example: Check if the word “FlowMattic” exists in the input text.
3. Replace Text
Search for a specific string and replace it with another string.
- Example: Replace the word “error” with “issue” in a log file.
4. Basic Formatting
Perform basic text formatting operations such as capitalization, case conversion, and extracting specific data.
- Available Options:
-
Capitalize
Capitalize the first letter of each word. Example: “hello world” returns “Hello World”.
-
Title Case
Capitalize the first letter of each word except for articles, conjunctions, and prepositions. Example: “the quick brown fox” returns “The Quick Brown Fox”.
-
Upper Case
Convert all letters to uppercase. Example: “hello world” returns “HELLO WORLD”.
-
Lower Case
Convert all letters to lowercase. Example: “HELLO WORLD” returns “hello world”.
-
Sentence Case
Capitalize the first letter of the first word. Example: “hello world” returns “Hello world”.
-
Remove HTML Tags
Remove HTML tags from the text. Example: “
Hello, world!
” returns “Hello, world!”. -
Extract Numbers
Extract numbers from the text. Example: “abc123def” returns “123”.
-
Extract Email Address
Extract email addresses from the text. Example: “Contact us at [email protected] for assistance.” returns an array of emails like - [“[email protected]”].
-
Extract Phone Numbers
Extract phone numbers from the text. Example: “Call us at 123-456-7890 for more information.” returns all phone numbers like - phone_0: “123-456-7890”.
-
Extract URLs
Extract URLs from the text. Example: “Visit our website at https://www.domain.com for more information.” returns all URLs like - url_0: “https://www.domain.com”.
-
Get Length of String
Get the length of the input text. Example: “Hello, world!” returns 13.
-
Get Word Count
Get the number of words in the input text. Example: “Hello, world!” returns 2.
-
Trim White Space
Remove leading and trailing white spaces from the text. Example: " Hello, world! " returns “Hello, world!”.
-
5. Split Text
Split text based on a specific character or word and return a segment.
- Example: Split a full name into first and last names using a space as the delimiter. eg. “John Doe” returns as -
item_0: John item_1: Doe
Split Text action comes with the following options -
- Content to Split
- Provide the text to be split. You can map the content from previous steps response.
- Seperator
- Provide the character or word to split the text. Default is a comma (,). To split based on a space, use [space] as the separator.
- Segment Index
- Segment of text to return after splitting. Available options are -
- First : Returns the first segment of the split text.
- Second : Returns the second segment of the split text.
- Last : Returns the last segment of the split text.
- Second to Last : Returns the second to last segment of the split text.
- All : Returns all segments of the split text as an array.
- Segment of text to return after splitting. Available options are -
6. Text Between
Extract text between two specified strings.
You need to provide the text to search in and the start and end strings to extract the text between them.
- Example: Extract the price from a product description between the strings “Price: $” and “USD”.
Product Description: "This product is available at a Price: $100 USD." Start Text: "Price: $" End Text: " USD" Extracted Text: "100"
7. Default Value
Sometimes, the response generated in previous step might be empty. In such cases, you can set a default value to be used instead. Set the default value for the response from previous step you want to use, and it will return the response value if available or the default value if not.
- Example: Set a default value for webhook response key “price” as “Not Available” if the key is empty.
Field: webhook1.price
Default Value: Not Available
8. Truncate
Limit text to a specific character length and truncate the rest.
- Example: Shorten a product description to 100 characters for a preview.
9. URL Encode
Encode text for safe use in URLs.
- Example: Convert spaces in a query string to
%20
.
10. URL Decode
Decode URL-encoded text back to its original form.
- Example: Decode
%20
back to spaces in a URL string.
Tips for Best Practices
- Use Extract Pattern with carefully crafted regex to avoid unintended matches.
- Combine Split Text and Text Between for advanced text parsing scenarios. Eg. Extracting data from structured text.
- Always test your workflows with sample data to ensure the desired output.
The Text Formatter module is highly versatile and can be integrated into various workflow scenarios, such as data cleaning, text extraction, and formatting.
By leveraging the Text Formatter module, you can streamline text processing tasks and enhance the efficiency of your workflows. If you have any questions or need assistance with a specific use case, feel free to reach out to our support team for guidance and support.