All guides
HubSpotTutorialAdvanced

Useful Regex Patterns for HubSpot Search and Replace

By SearchReplace··7 min read

Regex — regular expressions — can feel intimidating if you haven't used them before. But for HubSpot data cleanup, you don't need to be a regex expert. A handful of practical patterns cover the vast majority of real-world scenarios: standardizing phone numbers, fixing URLs, cleaning up email addresses, and normalizing text formatting.

This guide provides copy-paste regex patterns for common HubSpot search-and-replace operations. Each pattern is explained in plain language so you understand what it matches and why, not just how to use it.

Here's a regex pattern in action — stripping HTML tags from contact notes:

Quick regex primer

If you're new to regex, here are the building blocks used in the patterns below:

SymbolMeaningExample
.Any single charactera.c matches "abc", "a1c", "a-c"
*Zero or more of the previousab*c matches "ac", "abc", "abbc"
+One or more of the previousab+c matches "abc", "abbc" but not "ac"
?Zero or one of the previouscolou?r matches "color" and "colour"
\dAny digit (0-9)\d\d\d matches "123", "456"
\sAny whitespacehello\sworld matches "hello world"
\bWord boundary\bcat\b matches "cat" but not "category"
[...]Any character in the set[aeiou] matches any vowel
(...)Capture groupUsed to reference matched text in replacements
\1Back-reference to group 1Used in the search pattern to match the same text again
^Start of string^Hello matches "Hello world"
$End of stringworld$ matches "Hello world"

In replacement strings, captured groups are referenced as $1, $2, etc.

Phone number patterns

Standardize US phone numbers to (XXX) XXX-XXXX

Many HubSpot portals have phone numbers in a dozen different formats. This pattern matches most common US phone number formats and lets you standardize them.

Search pattern:

\+?1?[\s.-]?\(?(\d{3})\)?[\s.-]?(\d{3})[\s.-]?(\d{4})

Replacement:

($1) $2-$3

What it matches:

  • 5551234567
  • 555-123-4567
  • (555) 123-4567
  • 555.123.4567
  • 1-555-123-4567
  • +1 555 123 4567
  • +15551234567

What it produces: (555) 123-4567 in every case.

Add country code to US phone numbers

If you need to standardize to international format:

Search pattern:

\+?1?[\s.-]?\(?(\d{3})\)?[\s.-]?(\d{3})[\s.-]?(\d{4})

Replacement:

+1$1$2$3

Result: +15551234567

URL patterns

Replace HTTP with HTTPS

If your CMS content or CRM records contain links using http://, you can upgrade them to https://:

Search pattern:

http://

Replacement:

https://

This is a simple literal replacement — no regex needed. But if you want to be precise and avoid double-converting already-HTTPS URLs (in case a property contains the literal text "http://https://"), you can use:

Search pattern:

(?<!s)http://

Replacement:

https://

The (?<!s) is a negative lookbehind that prevents matching if "http" is preceded by "s" (i.e., it won't match inside "https://").

Update a domain across all content

When a company you link to changes domains:

Search pattern:

oldpartner\.com

Replacement:

newpartner.io

Note the escaped dot (\.). In regex, a bare . matches any character, so oldpartner.com would also match oldpartnerXcom. Escaping the dot ensures you only match the literal period.

Fix trailing slashes

Standardize URLs to not have trailing slashes (or to always have them):

Search pattern (remove trailing slashes):

(https?://[^\s"']+[^/\s"'])/+(\s|$|[)"'])

Replacement:

$1$2

This is a more advanced pattern. In practice, if you just need to fix a specific set of URLs, literal replacements are simpler and safer.

Email domain patterns

Fix common email domain typos

Users frequently mistype popular email domains. These patterns catch the most common ones:

Gmail typos:

SearchReplace
@gmial\.com@gmail.com
@gmal\.com@gmail.com
@gamil\.com@gmail.com
@gmail\.co$@gmail.com
@gnail\.com@gmail.com

Other common typos:

SearchReplace
@yaho\.com@yahoo.com
@yahooo\.com@yahoo.com
@hotmal\.com@hotmail.com
@outloo\.com@outlook.com

Run each of these as a separate search-and-replace operation. Preview the results before applying — you don't want to "fix" a legitimate domain that happens to look like a typo.

Find personal email addresses

To identify contacts using personal email providers (useful for filtering B2B records):

Search pattern:

@(gmail|yahoo|hotmail|outlook|aol|icloud|mail|protonmail|zoho)\.(com|co\.uk|de|fr)$

This pattern is useful for searching and identifying records, even if you don't want to replace the values — use it to find contacts, then manually decide what to do with them.

Text cleanup patterns

Remove extra whitespace

Clean up fields with double spaces, leading spaces, or trailing spaces:

Search pattern (double spaces):

  +

Replacement:

(That's two-or-more spaces replaced with a single space.)

Search pattern (leading whitespace):

^\s+

Replacement: (empty string)

Search pattern (trailing whitespace):

\s+$

Replacement: (empty string)

Fix smart quotes and special characters

Data imported from Word documents or rich text editors often contains smart quotes and em dashes that display as garbage characters in some systems:

SearchReplace
\u2018 or \u2019'
\u201C or \u201D"
\u2013-
\u2014--

Note: Whether Unicode escape sequences work depends on your tool's regex engine. You may need to paste the actual characters instead.

Standardize capitalization artifacts

If data was imported in ALL CAPS and you want to flag those records:

Search pattern:

^[A-Z\s]{10,}$

This matches values that are entirely uppercase letters and spaces, at least 10 characters long. It's useful for identifying records that need capitalization cleanup, though the actual case conversion usually requires a script or spreadsheet formula.

Company name patterns

Standardize company suffixes

Search (find inconsistent suffixes):

SearchReplace
\bInc$Inc.
\bIncorporated$Inc.
\bLLC$LLC
\bL\.L\.C\.$LLC
\bLtd$Ltd.
\bLimited$Ltd.

The \b word boundary prevents matching "Included" when searching for "Inc," and the $ anchors the match to the end of the string so you're only matching suffixes, not text in the middle of a company name.

Remove "The" prefix

Some companies are entered as "The Acme Corporation" while others are just "Acme Corporation":

Search pattern:

^The\s+

Replacement: (empty string)

Preview carefully — "The New York Times" should probably keep its "The."

Country and state standardization

US country value standardization

Run these in order, from most specific to least:

SearchReplace
^United States of America$United States
^U\.S\.A\.$United States
^USA$United States
^U\.S\.$United States
^US$United States

Using ^ and $ anchors ensures you're matching the entire field value, not a substring. Without anchors, searching for "US" would match "Australia" and "Russia."

Tips for safe regex in HubSpot

  1. Always preview first. Regex can match more than you expect. Review every match before applying changes.

  2. Start specific, then broaden. Begin with a narrow pattern that matches known cases. Only widen the pattern if you find additional variations.

  3. Use anchors when matching entire values. ^US$ is much safer than US alone.

  4. Test on a small dataset. If your tool allows it, test the pattern on a filtered set of records before running it across your entire database.

  5. Keep a log. Document each pattern you run, what it matched, and how many records were affected. This helps you audit changes and builds a library of patterns you can reuse.

Regex is a powerful tool, but it's also an unforgiving one. A misplaced character can match thousands of unintended records. The combination of regex power with a preview-before-commit workflow is what makes it practical for CRM data cleanup rather than terrifying.

Related HubSpot guides for planning, previewing, and validating the next step.

Still editing HubSpot records one by one?

Start with 100 free applied records — no credit card required.