When utilizing data fields in various scenarios such as saving emails to folder or printing emails with fields or sending a message to Telegram, it is possible to extract only a portion of the data or change a value. This functionality proves useful when dealing with lengthy strings and you only require a specific section, such as an email or an order number.
Example: let's consider a scenario where you want to save an email to a folder using the email's unique ID as part of the folder or filename. However, the ID is quite long, like "%22456464xcvrg4vcv@sgdcv12%". In this case, you can extract only the last 4 digits by using the following function: RIGHT(%EMAIL_ID%, 4).
The following functions are available for your use:
- LEFT(field,X) = extract the X number of characters from the start (for example LEFT("Order received from King of Flowers", 5) return "Order")
- RIGHT(field,X) = extract the X number of characters from the end (for example RIGHT("Order received from King of Flowers", 7) return "Flowers")
- MID(field,X,Y) = extract the Y number of characters from the X position (for example MID("Order received from King of Flowers", 6, 8) return "received")
- REPLACE(field,SearchValue,ReplaceValue) = replace the SearchValue by the ReplaceValue, for example REPLACE(%EMAIL_BODY_TEXT%,Bearish,Sell)
- REMOVE(field,RemoveValue) = remove the value in the string, for example REMOVE(%EMAIL_BODY_TEXT%,Bearish)
- REGEX() = use regular expressions to extract data, this function is particular and requires some computer skills. For more information on RegEx please check these sites:
https://blog.usejournal.com/regular-expressions-a-complete-beginners-tutorial-c7327b9fd8eb
Here some basic examples to use REGEX in the fields: - Extract all numbers in the email subject field: REGEX(%EMAIL_SUBJECT%,[0-9]+) - Exclude the characters #: in the attachment filename: REGEX(%FILENAME_FULL%,[^#]) - Exclude some keywords: in the attachment filename: REGEX(%FILENAME_FULL%,[^invoice|^factuur]) - Exclude the characters FW: in subject of email: REGEX(%EMAIL_SUBJECT%,[^FW:]) - Extract words ending with .mp3 or .mp4 or .avi: REGEX(%EMAIL_ATTACHMENT_LIST_FULL%,\w+\.(mp3|mp4|avi)\b) - Extract text between a word and another: REGEX(%EMAIL_BODY%,(?<=My words).[^last word]*) - Extract message till a specific word: REGEX(%EMAIL_BODY_TEXT%,^[\s\S]*?(?=TheWord))