Extract text, change case and parse JSON
Mammoth has three text functions: Extract Text pulls a piece out of a value, Text Formatting fixes case and spacing, and Extract JSON turns JSON into columns or rows (Parse a JSON column). Open them from the Describe your transformation bar (or a + button in the Pipeline panel) › Date, Numeric & Text. Each one is a pipeline task that runs again every time the pipeline refreshes.
Extract part of a text value
Extract Text pulls a pattern out of a text column. Describe what you want in plain words and Mammoth builds the pattern, or pick a method and set it up yourself.
- In Select column, choose the text column.
- In Select extraction method, choose how to define the pattern. The default is Custom Prompt. The methods are described below.
- Optional: click Add Condition to extract only from rows that meet a condition.
- In Place in, choose New Column and type a name, or choose Existing Column.
- Click Apply.
Describe what to extract with Custom Prompt
Type what you want to pull out and click Generate. Mammoth writes a regular expression (regex, a text pattern) and shows a live example from your own data, for example "Cotton T-Shirt will result in Shirt."
To change the pattern, click the edit icon next to the regex. The Edit Regex modal opens. Change the Regex Formula field and click Save changes.
Pick a pattern-based method
These show a few inputs, such as a direction, a character count or a value to match, and an example from your column that updates as you type:
- Characters around a letter / word
- Characters from beginning or to end
- Characters in a certain position
- Contains a number
- Does not contain a number
- Does not end with
- Does not end with a number
- Does not start with
- Does not start with a number
- Ends with
- Ends with a number
- Starts with
- Starts with a number
Write your own regular expression
Choose Regular expression or All except regular expression and type a regex in the text field. An example updates as you type.
| Method | What it extracts |
|---|---|
| Regular expression | The text that matches the pattern |
| All except regular expression | Everything that does not match the pattern |
Example: a product_code column holds values like "REF-2045 Blue Widget". Use Custom Prompt with "extract the code before the first space" to get "REF-2045" in a new column. To take the first 3 characters of every value, use Characters from beginning or to end, set the direction to Beginning and enter 3.
Change text to upper, lower or capital case and trim spaces
Text Formatting makes the case or spacing of one or more text columns consistent. You can format several columns at once and limit it to some rows with a condition.
- In Select columns, tick one or more text columns. They appear as chips under Review selected columns. Click the X on a chip to remove it, or click Clear to remove them all.
- Optional: click Add Condition to format only the rows that meet a condition.
- To change case, tick Change text case and choose UPPER CASE, lower case or Capital Case.
- To tidy spacing, tick Normalize whitespace. It removes spaces at the start and end, and extra spaces between words.
- Check the preview on the right, then click Apply.
Example: a category column from another system holds "shirts", "Shirts" and "SHIRTS" for the same thing. UPPER CASE turns them all into "SHIRTS", so they match when you join this data to another source.
Troubleshooting text functions
| Symptom | Cause | Fix |
|---|---|---|
| A join misses rows that look the same | Case or spacing differs between the two key columns | Run Text Formatting on both sides before the join. See Join two datasets on a shared column. |
| The Custom Prompt pattern picks up the wrong text | The description was too vague | Rephrase it, or open Edit Regex and correct the Regex Formula |
Related
- Parse a JSON column into columns or rows: Extract JSON.
- Find and replace values: standardise values that differ in more than case.
- Combine or split columns: split or combine text columns.
- Use AI on your columns: classify or rewrite text with a prompt.
Something wrong? support@mammoth.io