HubSpot Regex Find and Replace: Complete Guide
HubSpot doesn't have a built-in find-and-replace feature — not for CRM records, and not for CMS content. When you add regex (regular expressions) to the picture, the gap becomes even wider. Regex lets you match patterns instead of fixed strings, which is essential for cleaning up real-world CRM data where the same information appears in dozens of different formats.
This guide teaches you how to use regex for HubSpot find-and-replace operations. It assumes no prior regex knowledge and builds from basic concepts to practical, real-world examples you can use right away.
What is regex, and why does it matter for HubSpot?
A regular expression is a pattern that describes a set of strings. Instead of searching for the exact text "555-123-4567," you can write a pattern that matches any phone number — regardless of whether it's written as "555-123-4567," "(555) 123-4567," or "555.123.4567."
This matters for HubSpot data because CRM data is messy. It's entered by humans, imported from various sources, and accumulated over years. The same piece of information gets recorded in many different ways. Fixed-string search-and-replace can only fix one format at a time. Regex can fix all of them in a single operation.
Without regex: You'd need to run separate operations for each format:
- Replace
555-123-4567with(555) 123-4567 - Replace
555.123.4567with(555) 123-4567 - Replace
5551234567with(555) 123-4567 - ...and so on for every format variation
With regex: One operation handles all formats at once. Search for the pattern, replace with the standardized format.
Where to use regex with HubSpot
HubSpot itself doesn't support regex in its native interface. You can't type a regex into HubSpot's search bar or use it in the CRM filter view. To use regex with HubSpot data, you need either:
-
The HubSpot API — write a script that fetches records, applies regex matching and replacement, and pushes updates back. This requires developer skills.
-
A third-party tool — a bulk editing tool that connects to HubSpot and supports regex search-and-replace. SearchReplace supports regex patterns for both CRM and CMS operations.
-
CSV export + spreadsheet — export records, use regex-capable formulas (like Google Sheets' REGEXREPLACE function), and re-import. This works but adds the complexity and risk of the CSV round-trip.
Regex fundamentals for HubSpot users
Literal characters
Most characters in a regex match themselves. The pattern hello matches the text "hello." If all you need is a fixed-string search, you don't need any special regex syntax — just type what you're looking for.
Character classes
Square brackets define a set of characters to match:
[aeiou]— matches any single vowel[0-9]— matches any digit[a-zA-Z]— matches any letter (upper or lowercase)[^0-9]— matches anything that is NOT a digit (the^inside brackets means "not")
Shorthand classes are even more convenient:
\d— any digit (same as[0-9])\w— any word character (letter, digit, or underscore)\s— any whitespace (space, tab, newline)
Quantifiers
Quantifiers specify how many of the preceding character or group to match:
*— zero or more:\d*matches "", "1", "123"+— one or more:\d+matches "1", "123" but not ""?— zero or one:colou?rmatches "color" and "colour"{3}— exactly three:\d{3}matches "123" but not "12" or "1234"{2,4}— between two and four:\d{2,4}matches "12", "123", "1234"
Groups and capture
Parentheses create groups that serve two purposes:
- Grouping for quantifiers:
(abc)+matches "abc", "abcabc", etc. - Capturing for replacement: Whatever the group matches can be referenced in the replacement string as
$1(first group),$2(second group), etc.
This is the key feature for HubSpot data transformation. You match the parts of the data you want to keep, capture them in groups, and rearrange them in the replacement.
Anchors
Anchors match positions, not characters:
^— start of the string$— end of the string\b— word boundary (between a word character and a non-word character)
Anchors are critical for safety. Searching for US without anchors would match "Russia," "Australia," "USA," and "focus." Searching for ^US$ only matches the exact string "US."
Practical HubSpot examples
Here's a regex search-and-replace in action — reformatting phone numbers by capturing the area code and rearranging the format:
Example 1: Reformat dates
Your deal close dates were imported in DD/MM/YYYY format (European style) but HubSpot expects MM/DD/YYYY (US style). Some deals show the wrong date because the day and month were swapped.
Search:
^(\d{2})/(\d{2})/(\d{4})$
Replace:
$2/$1/$3
This swaps the first two groups: 15/03/2026 becomes 03/15/2026.
Important: Only run this on records you've confirmed have the wrong format. If some records are already in MM/DD/YYYY format, swapping them would make things worse. Filter to a specific import batch or date range first.
Example 2: Extract and standardize domains from URLs
You have a company URL field with values like https://www.acme.com/, http://acme.com, www.acme.com, and acme.com. You want just the clean domain.
Search:
^(?:https?://)?(?:www\.)?([^\s/]+)/?.*$
Replace:
$1
This strips the protocol (http:// or https://), the www. prefix, and any path after the domain. All four formats above become acme.com.
Example 3: Mask sensitive data
You need to partially redact credit card numbers or account numbers stored in a notes field:
Search:
\b(\d{4})\s?\d{4}\s?\d{4}\s?(\d{4})\b
Replace:
$1-XXXX-XXXX-$2
This keeps the first and last four digits, masking the middle: 4111 1111 1111 1234 becomes 4111-XXXX-XXXX-1234.
Example 4: Clean up HTML tags from plain text fields
Sometimes data imported from other systems includes HTML tags in fields that should be plain text:
Search:
<[^>]+>
Replace: (empty string)
This removes all HTML tags: <p>Hello <strong>world</strong></p> becomes Hello world.
Caution: This is a blunt tool. If the HTML contains important formatting or the field is supposed to contain HTML, don't use this pattern. Preview your results carefully.
Example 5: Normalize whitespace in addresses
Address fields often have inconsistent spacing — double spaces, spaces before commas, or no space after commas:
Search (multiple spaces):
{2,}
Replace:
Search (space before comma):
\s+,
Replace:
,
Search (no space after comma):
,([^\s])
Replace:
, $1
Run these in sequence: first collapse multiple spaces, then fix comma spacing.
Common mistakes and how to avoid them
Mistake 1: Forgetting to anchor
Searching for Inc to standardize company suffixes will also match "Included," "Incredible," and "Lincoln." Always use anchors or word boundaries: \bInc\.?$ matches "Inc" or "Inc." only at the end of a string, preceded by a word boundary.
Mistake 2: Greedy matching
By default, .* is "greedy" — it matches as much text as possible. In the string <b>hello</b> and <b>world</b>, the pattern <b>.*</b> matches the entire string (from the first <b> to the last </b>), not just <b>hello</b>.
Use .*? (lazy/non-greedy) to match as little as possible: <b>.*?</b> correctly matches <b>hello</b> and <b>world</b> separately.
Mistake 3: Not escaping special characters
In regex, these characters have special meaning: . * + ? ^ $ { } [ ] ( ) | \
To match a literal period, you need \. not . — because . matches any character. Searching for acme.com without escaping the dot would also match acmeXcom.
Mistake 4: Overly broad patterns
A pattern that's too broad will match unintended text. Always start with a specific pattern and broaden only if needed. And always preview the matches before applying the replacement.
Mistake 5: Testing only with expected data
Your regex might work perfectly on the data formats you know about but break on formats you haven't seen. A phone number field might contain "N/A," "call office," or "ext. 123" — values that don't look like phone numbers at all. A broad phone number regex might partially match these and produce garbled output.
Building confidence with regex
If regex is new to you, here's a practical learning path:
-
Start with literal replacements. No regex needed — just fixed string search-and-replace. This builds familiarity with the tool and the preview workflow.
-
Add simple character classes. Replace
\d(any digit) and\s(any whitespace) into your patterns. These handle most variation in data formatting. -
Learn capture groups. The
(...)and$1pattern is where regex becomes genuinely powerful. It lets you rearrange data, not just replace it. -
Use online regex testers. Sites like regex101.com let you test patterns against sample data and explain each part of the pattern in plain language. Build and test your pattern there, then use it in your HubSpot tool.
-
Always preview. Even experienced regex users preview their results. The preview step is your safety net — use it every time, without exception.
Regex is one of those skills that pays dividends far beyond HubSpot. Once you're comfortable with the basics, you'll find uses for it in spreadsheets, text editors, data analysis, and anywhere else you work with text data. The investment in learning is modest, and the payoff is significant.
Keep working through the cleanup
Related HubSpot guides for planning, previewing, and validating the next step.
Useful Regex Patterns for HubSpot Search and Replace
A practical collection of regex patterns for common HubSpot data cleanup tasks — phone numbers, URLs, email domains, and more.
Read guideHow to Bulk Edit Associations in HubSpot
HubSpot's association system links contacts to companies, deals to contacts, and more. Here's how to manage, fix, and bulk-update these associations when they break or need changing.
Read guideHow to Bulk Edit Date Properties in HubSpot
Date properties in HubSpot have specific format requirements and timezone handling that make bulk editing tricky. Here's how to update dates across many records without breaking things.
Read guideHow to Bulk Edit Multi-Select Properties in HubSpot
Multi-select properties in HubSpot are notoriously difficult to edit in bulk. Here's how they work under the hood and the best approaches for updating them across many records.
Read guideStill editing HubSpot records one by one?
Start with 100 free applied records — no credit card required.