Skip to content
Learn › Clean and shape data: open the docs menu

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.

  1. In Select column, choose the text column.
  2. In Select extraction method, choose how to define the pattern. The default is Custom Prompt. The methods are described below.
  3. Optional: click Add Condition to extract only from rows that meet a condition.
  4. In Place in, choose New Column and type a name, or choose Existing Column.
  5. 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.

Extract Text panel with event_id selected, the Custom Prompt method, a prompt, and result column Event_Key

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.

MethodWhat it extracts
Regular expressionThe text that matches the pattern
All except regular expressionEverything 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.

Text Formatting panel with two text columns selected and Change text case set to UPPER CASE
  1. 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.
  2. Optional: click Add Condition to format only the rows that meet a condition.
  3. To change case, tick Change text case and choose UPPER CASE, lower case or Capital Case.
  4. To tidy spacing, tick Normalize whitespace. It removes spaces at the start and end, and extra spaces between words.
  5. 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

SymptomCauseFix
A join misses rows that look the sameCase or spacing differs between the two key columnsRun Text Formatting on both sides before the join. See Join two datasets on a shared column.
The Custom Prompt pattern picks up the wrong textThe description was too vagueRephrase it, or open Edit Regex and correct the Regex Formula
Was this page helpful?

Something wrong? support@mammoth.io