If Contains Google Sheets: Substring Checks with IF

Learn practical techniques to detect substrings in Google Sheets using IF with REGEXMATCH and SEARCH. This guide covers robust patterns, case handling, and common pitfalls for students, professionals, and teams.

How To Sheets
How To Sheets Team
·5 min read
Substring Checks in Sheets - How To Sheets
Photo by sphotoeditvia Pixabay
Quick AnswerDefinition

IF and contains checks in Google Sheets help you detect whether a cell holds a substring. The usual approach is to wrap a contains test inside an IF statement using REGEXMATCH or SEARCH. For example: =IF(REGEXMATCH(A2, \"poll\"), \"Found\",\"Not found\") and =IF(ISNUMBER(SEARCH(\"poll\", A2)), \"Found\",\"Not found\"). These patterns cover simple to moderately complex text filtering tasks. Learning to combine them with array formulas expands coverage across rows.

Overview: Understanding 'if contains google sheets' in practice

In Google Sheets, a common data-cleaning task is to test whether a cell's text includes a particular substring. The phrase 'if contains google sheets' often means you want to return one value when the substring exists and another when it does not. There are several reliable patterns for this, with REGEXMATCH and SEARCH being the most frequently used. The key is choosing the right tool for your data: exact vs. flexible matching, case sensitivity, and how you want to handle multiple results.

Excel Formula
=IF(REGEXMATCH(A2, "poll"), "Found","Not found")
Excel Formula
=IF(ISNUMBER(SEARCH("poll", A2)), "Found","Not found")

Explanation: REGEXMATCH checks the text against a regular expression and returns TRUE when the pattern is found. SEARCH returns the position of the substring (a number) or an error if not found; ISNUMBER converts that to a boolean. For exact-case matching you may use FIND, which is case-sensitive.

Excel Formula
=IF(ISNUMBER(FIND("Poll", A2)), "Found","Not found")

codeBlocksCountedForPattern1WhileExplainingCodeBlockInThisSectionNoteOnly

Steps

Estimated time: 30-45 minutes

  1. 1

    Set up test data

    Create a simple sheet with a text column (A) and a test substring (e.g., 'poll') to look for. This baseline helps verify multiple approaches work as expected.

    Tip: Label your test column so you can track which rows are matched.
  2. 2

    Try REGEXMATCH for contains

    Use REGEXMATCH to check if the text contains a substring. Start with a straightforward pattern and then broaden as needed.

    Tip: Regex patterns are powerful; start simple and add alternatives with | for OR logic.
  3. 3

    Fallback with SEARCH or FIND

    If you prefer position-based checks, combine ISNUMBER with SEARCH (case-insensitive) or FIND (case-sensitive) to drive IF results.

    Tip: SEARCH is case-insensitive; FIND is case-sensitive.
  4. 4

    Handle multiple substrings

    Use OR and REGEXMATCH to test multiple substrings in one go, which is efficient for data validation.

    Tip: Avoid repeated REGEXMATCH calls by combining patterns when practical.
  5. 5

    Scale with ARRAYFORMULA

    Apply tests to entire columns without dragging formulas by wrapping with ARRAYFORMULA and referencing full ranges.

    Tip: Be mindful of performance on very large datasets.
Pro Tip: Prefer REGEXMATCH for flexible, pattern-based contains checks.
Warning: Regex patterns can fail with special characters; escape them or sanitize input.
Note: Use ARRAYFORMULA to apply checks across many rows efficiently, but test performance on large sheets.
Warning: When using FIND, remember it is case-sensitive; use SEARCH for case-insensitive needs.

Prerequisites

Required

Optional

Keyboard Shortcuts

ActionShortcut
CopyCopy cell or formulaCtrl+C
PastePaste cell or formulaCtrl+V
Paste values onlyPaste only the value resultsCtrl++V
Fill downPropagate a formula down a columnCtrl+D

FAQ

What is the difference between REGEXMATCH and SEARCH for contains checks?

REGEXMATCH tests text against a pattern and returns TRUE when any match is found. SEARCH returns the position of the substring or an error; ISNUMBER converts that to a boolean. REGEXMATCH is more flexible for complex patterns, while SEARCH is simpler for straightforward containment.

REGEXMATCH is for patterns, while SEARCH finds a substring position. REGEXMATCH is more flexible for complex text.

Can I check multiple substrings at once?

Yes. You can combine REGEXMATCH with patterns like poll|survey to test several substrings in one go, or use OR with separate REGEXMATCH calls. This reduces the number of formulas you need to maintain.

You can test several substrings by using poll|survey inside REGEXMATCH or by OR-ing multiple checks.

How do I ensure case-insensitive matching?

REGEXMATCH patterns are case-sensitive by default, but you can apply LOWER to both sides or design a pattern without case sensitivity using a broad approach. Alternatively, use SEARCH, which is naturally case-insensitive.

Use LOWER on both sides or switch to SEARCH for a case-insensitive check.

What happens if the cell is empty or contains errors?

If a cell is empty, REGEXMATCH returns FALSE and SEARCH returns an error that ISNUMBER will handle by returning FALSE. It’s good practice to wrap tests with IFERROR or ISBLANK for robust sheets.

Empty cells usually yield a FALSE result; handle errors with IFERROR for clean outputs.

Can I apply these checks to an entire column efficiently?

Yes. Use ARRAYFORMULA to apply the test to an entire column, e.g., =ARRAYFORMULA(IF(REGEXMATCH(A2:A, "poll"), "Found","Not found")). Always test on a sample before scaling to full data.

Use ARRAYFORMULA to apply the test down the whole column.

The Essentials

  • Use REGEXMATCH for versatile contains tests
  • Prefer SEARCH for case-insensitive checks
  • Use ARRAYFORMULA for column-wide validation
  • Escape special characters in regex patterns
  • Test with real data to avoid false positives

Related Articles