This documentation provides a comprehensive explanation of the string functions available in our system.
Table of Contents
DATA_SELECT Function
The DATA_SELECT
function allows you to extract specific information from data formatted in JSON, XML, or HTML. It takes two arguments:
-
Data Type: This specifies the format of your data, either
"JSON"
,"XML"
, or"HTML"
. -
Selector: This defines the path to the desired information within the data. It uses a dot notation similar to navigating directories on a computer.
Key Points:
DATA_SELECT(JSON)[data.array~2.name] |
This example extracts the value of the "name"
property within the second element of the "array"
property from JSON data.
-
The
~
symbol indicates an array position (e.g.,array~2
refers to the second element). -
You can use nested selectors to navigate deeper within the data structure.
JSON Example:
Syntax:
DATA_SELECT(JSON)[data.array~2.name] |
JSON:
{ "data": { "array": [ { "name": "Item 1" }, { "name": "Item 2" }, { "name": "Item 3" } ] } } |
Explanation:
-
We want to extract the value of the
"name"
property within the second element (~2
) of the"array"
property. -
The selector navigates through the JSON structure using dot notation.
Result: Using the DATA_SELECT(JSON)[data.array~2.name]
function would return the string: "Item 3"
.
HTML Example:
Syntax:
DATA_SELECT(HTML)[html.body.table.tr~2.td~1.text.innerText] |
HTML:
<!DOCTYPE html> <html> <body> <table> <tr> <th>Name</th> <th>Description</th> </tr> <tr> <td>Item 1</td> <td>A great product</td> </tr> <tr> <td>Item 2</td> <td>This is the content we want to extract</td> </tr> <tr> <td>Item 3</td> <td>Another product</td> </tr> </table> </body> </html> |
Explanation:
-
We want to extract the text content from the second table row (
table
) in the HTML. -
Inside that row, we target the first table cell (
tr~2.td~1
). -
Finally, we use
.text.innerText
to specify that we want the inner text content of that cell.
Result:
Using the provided DATA_SELECT
function would extract the value: "This is the content we want to extract"
.
XML Example:
Syntax:
DATA_SELECT(XML)[data.array.item[2].name] |
XML:
<data> <array> <item> <name>Item 1</name> </item> <item> <name>Item 2</name> </item> <item> <name>Item 3</name> </item> </array> </data> |
Explanation:
-
We want to extract the text content of the
"name"
element within the second ([2]
) child element (item
) of the parent element (array
) named"data"
. -
The selector uses square brackets to specify the position of the child element within its parent.
Result: Using the DATA_SELECT(XML)[data.array.item[2].name]
function would return the string: "Item 3"
.
REGEX_REPLACE Function
The REGEX_REPLACE
function helps you modify text by searching for a specific pattern (using regular expressions) and replacing it with another value. It takes two arguments:
-
Regex Pattern: This defines the pattern you want to find in the text. Regular expressions are a powerful tool for complex text matching, but there are resources available online for learning the basics.
-
Replacement Value: This specifies what you want to replace the matched pattern with. It can be empty (to remove the pattern) or any other text.
Key Points:
REGEX_REPLACE([^a-z])[""] {{ [F].[description] }} |
This example removes all characters except lowercase letters ([a-z]
) from the content stored in the field named "description"
associated with variable [F]
.
-
Regular expressions can be complex, so refer to online resources for detailed explanations.
-
The
[^]
syntax within the pattern matches any character except those listed inside the brackets.
Example:
Syntax:
REGEX_REPLACE([pattern])[replacement]{{content}} |
Text:
We are having a sale on products this weekend! SALE! SALE! |
Explanation:
-
We want to remove all instances of the word "SALE!" (including the exclamation mark) from the text.
REGEX_REPLACE Function:
-
Pattern:
SALE!
(case-sensitive)-
This pattern matches the literal text "SALE!" exactly.
-
-
Replacement:
""
(empty string)-
This replaces all matched patterns with nothing, effectively removing them.
-
Final Code:
REGEX_REPLACE(SALE!)[""]{{We are having a sale on products this weekend! SALE! SALE!}} |
Result with Function:
Using the REGEX_REPLACE(SALE!)[""]{{We are having a sale on products this weekend! SALE! SALE!}}
function would modify the text to: "We are having a sale on products this weekend! " (Note the space after the weekend).
EXTRACT Functions:
The EXTRACT_REMOVE
function, along with the related functions EXTRACT_ALL
, EXTRACT_FIRST
, and EXTRACT_LAST
, allow you to manipulate text based on a predefined list of values. These functions require you to create a list (named using the List_
prefix) containing the values you want to target.
-
EXTRACT_REMOVE
: This function removes all occurrences of the values in your list from the text. -
EXTRACT_ALL
: This function joins all occurrences of the values in your list, separated by the delimiter defined for the list (usually a comma,
). -
EXTRACT_FIRST
: This function extracts the first occurrence of a value from your list within the text. -
EXTRACT_LAST
: This function extracts the last occurrence of a value from your list within the text.
Key Points:
List_Colors = Red, Green, Blue EXTRACT_REMOVE(List_Colors) {{ [F].[description] }} |
This example removes the words "Red", "Green", and "Blue" from the content stored in the field named "description"
associated with variable [F]
.
-
You need to define your lists separately using the
List_
prefix followed by the list name and the values separated by commas. -
The chosen
EXTRACT
function determines how the list values are handled within the text.
Example:
Syntax:
EXTRACT_REMOVE(List_Name){{content}} |
Text:
This product is free for a limited time, don't miss this chance! Get yours today or while supplies last. |
Explanation:
-
We want to remove promotional phrases like "free for a limited time", "don't miss this chance", "get yours today", and "while supplies last".
List Creation:
Before using EXTRACT_REMOVE
, you need to define a list containing the words or phrases you want to remove. You can create one by navigating to app.godatafeed.com/product#/product/lists.
Here, we'll name it List_Promotions
.
List_Promotions = free for a limited time, don't miss this chance, get yours today, while supplies last |
EXTRACT_REMOVE Function:
-
The function uses the list you created (separated by commas in this case).
Final Code:
List_Promotions = free for a limited time, don't miss this chance, get yours today, while supplies last EXTRACT_REMOVE(List_Promotions){{This product is free for a limited time, don't miss this chance! Get yours today or while supplies last.}} |
Result with Function:
Using the List_Promotions
and EXTRACT_REMOVE
function together would modify the text to: "This product is ." (Note the period at the end). It removes all promotional phrases defined in the list.
Additional Notes:
-
This documentation provides a basic overview of the functions. For more advanced usage scenarios, refer to the code comments within the system.
-
If you encounter any issues or have further questions, feel free to consult the system documentation or contact support.
Comments
0 comments
Please sign in to leave a comment.