Trim Text After a Character in Google Sheets: Step-by-Step Guide

Learn reliable methods to trim text after a delimiter in Google Sheets using LEFT, FIND, TEXTBEFORE, TEXTAFTER, and REGEXREPLACE. Step-by-step examples and best practices for robust data cleaning.

How To Sheets
How To Sheets Team
·5 min read
Quick AnswerSteps

Goal: Trim text after a chosen delimiter in Google Sheets. You can quickly do this with simple formulas like LEFT combined with FIND to extract text before the delimiter, or use TEXTBEFORE to grab everything before a specified character. For more complex patterns, REGEXREPLACE or TEXTAFTER provide robust, scalable options. This guide covers practical, copy-ready approaches.

What trimming after a character means in Google Sheets

In data-cleaning tasks, you often need the portion of a string that appears before a particular delimiter (such as a comma, dash, or colon). Trimming after a character means removing everything from that delimiter onward, leaving only the pre-delimiter text. This is a common requirement when standardizing identifiers, product codes, or names for downstream analysis. In Google Sheets, you can implement this with formulas that range from straightforward to advanced, depending on how predictable your data is. A robust approach reduces manual edits and helps keep datasets consistent across your spreadsheets.

Core techniques: LEFT, FIND, and TEXTBEFORE

The simplest method uses LEFT with FIND. For example, to keep text before a dash in cell A2: =LEFT(A2, FIND("-", A2) - 1). This finds the dash and returns everything to the left of it. If the delimiter might be missing in some cells, wrap the formula in IFERROR: =IFERROR(LEFT(A2, FIND("-", A2) - 1), A2). This ensures that cells without the delimiter simply return the original text. For multi-character delimiters, replace the dash with the full string and adjust the formula accordingly. This technique is fast and easy for clean, uniform data.

Using TEXTBEFORE and TEXTAFTER for cleaner syntax

TEXTBEFORE returns the text before a delimiter with a concise syntax: =TEXTBEFORE(A2, "-"). If the delimiter isn’t found, you can add a fallback value or use a different approach. TEXTAFTER provides the portion after the delimiter: =TEXTAFTER(A2, "-"). In trimming before a delimiter, TEXTBEFORE is typically the simplest and most readable option, and it handles edge cases more gracefully than LEFT/FIND in some scenarios.

Using REGEXREPLACE for pattern-based trimming

REGEXREPLACE is powerful for pattern-based trimming, including multiple delimiters or more complex strings. To trim after the first dash: =REGEXREPLACE(A2, "-.", ""). This removes the dash and everything after it. To trim after a comma, swap the dash for a comma: =REGEXREPLACE(A2, ",.", ""). You can extend to multiple delimiters with a character class, e.g., =REGEXREPLACE(A2, "[;:,].*", ""). Keep in mind that regular expressions can be tricky; test your patterns on representative data before applying to large ranges.

Practical scenarios: trimming after comma, colon, or space

Scenario A — trim before the first comma: =TEXTBEFORE(A2, ","). Scenario B — trim before a colon with fallback: =IFERROR(TEXTBEFORE(A2, ":"), A2). Scenario C — trim before the first space (useful for extracting first names): =LEFT(A2, FIND(" ", A2 & " ") - 1). If a delimiter is missing, these formulas can return an empty string or the original value unless you add IFERROR. For robustness, combine with TRIM to remove extraneous spaces: =TRIM(TEXTBEFORE(A2, ",")).

Tips for robustness and edge cases

  • Pro tip: Always test formulas on a small sample before applying to large ranges. - Warning: If the delimiter appears at the start of a string, LEFT/FIND methods may return an empty result; using TEXTBEFORE avoids this. - Note: When trimming, consider wrapping results in TRIM to remove unwanted spaces. - Note: If you need the nth occurrence of a delimiter, you may need SPLIT or a more complex regex pattern to select the correct segment.

Tools & Materials

  • Computer or mobile device with internet access(Open Google Sheets in a supported browser)
  • Google account(Access Google Sheets via Drive)
  • Sample dataset with delimiters(Prepare a column containing strings with dash, comma, colon, etc.)
  • Reference sheet for formulas(Optional for demonstrations and notes)
  • Notepad or notes field(Document chosen delimiter and formula logic)

Steps

Estimated time: 10-15 minutes

  1. 1

    Identify the delimiter and target cells

    Scan your data to determine which character marks the trim point (e.g., -, :, ,) and note the cells or column you will transform.

    Tip: Choose a delimiter that is not part of the non-target text to avoid accidental trimming.
  2. 2

    Apply LEFT/FIND for simple trims

    Enter a formula like =LEFT(A2, FIND("-", A2) - 1) and test on a few rows to confirm it cuts before the delimiter.

    Tip: Wrap with IFERROR to handle missing delimiters and keep data intact.
  3. 3

    Try TEXTBEFORE for cleaner syntax

    If available, use =TEXTBEFORE(A2, "-") for a concise solution that gracefully handles missing delimiters.

    Tip: TEXTBEFORE cleanly returns the pre-delimiter text and is easier to read.
  4. 4

    Use REGEXREPLACE for complex patterns

    For multiple or irregular delimiters, apply =REGEXREPLACE(A2, "-.*", "").

    Tip: Test regex patterns on sample data to ensure they capture the intended portion.
  5. 5

    Extend to ranges and finalize

    Drag the formula down to apply to a whole column, then copy-paste values to finalize the trimmed data.

    Tip: Consider wrapping in TRIM if extra spaces appear after trimming.
Pro Tip: Test each delimiter-based approach on a representative sample before applying to the full dataset.
Warning: Delimiters at the start or not present in a string can yield empty results; prefer TEXTBEFORE or IFERROR-based solutions.
Note: Keep a backup of the original data in a separate sheet or column for safety.
Pro Tip: Document which method you used (TEXTBEFORE, LEFT/FIND, or REGEXREPLACE) to help future users understand the logic.

FAQ

What is the easiest way to trim text before a delimiter in Google Sheets?

TEXTBEFORE is typically the simplest, most readable method. For a delimiter that might be missing, pair it with IFERROR to fall back to the original string.

TEXTBEFORE is usually the easiest approach; add IFERROR if some cells lack the delimiter.

How do I handle missing delimiters in the data when trimming?

Wrap the trimming formula in IFERROR or use a fallback value so cells without the delimiter don’t return errors or blanks.

If the delimiter isn’t found, use IFERROR to return the original text or a default value.

Can I trim after the second occurrence of a delimiter?

Yes, but it’s more complex. You can use REGEXREPLACE with a count or combine TEXTSPLIT and INDEX, depending on your data and availability of functions.

You can target the second occurrence with regex or split-based approaches.

What’s the difference between TEXTBEFORE and LEFT/FIND for trimming?

TEXTBEFORE is generally cleaner and safer for missing delimiters; LEFT/FIND is fast but needs careful error handling and may be brittle with edge cases.

TEXTBEFORE is the go-to for clean trims; LEFT/FIND works but needs safeguards.

Are there performance concerns when trimming text in very large sheets?

For large datasets, prefer native functions (TEXTBEFORE/TextAFTER/REGEXREPLACE) and minimize multi-step array formulas. Test performance on a subset first.

Performance matters—test on a small sample before scaling up.

Watch Video

The Essentials

  • Choose the simplest reliable method first (TEXTBEFORE or LEFT/FIND).
  • Handle missing delimiters with IFERROR or a fallback value.
  • REGEXREPLACE is powerful for complex patterns and multiple delimiters.
  • Wrap results with TRIM if needed to clean spacing.
  • Test across edge cases before applying to entire ranges.
Infographic showing step-by-step process to trim text after a delimiter in Google Sheets

Related Articles