Advanced Regex in Screaming Frog for Precision Link Analysis
When performing comprehensive link analysis, simply counting links isn’t enough. Sometimes, you need to filter, categorize, or extract specific patterns of URLs, attributes, or text content within your crawl data. This is where the power of Regular Expressions (Regex) within Screaming Frog SEO Spider comes into play. Advanced regex capabilities transform the tool from a basic crawler into a highly customizable data extraction and analysis machine.
This guide will dive deep into using advanced regex features in Screaming Frog to perform sophisticated link analyses, ensuring maximum precision and actionable insights.
🛠️ Understanding Where Regex is Used in Screaming Frog
Regex in Screaming Frog is not limited to a single field. It can be applied to various elements within the crawled data, including:
- Custom Extraction: Writing patterns to pull specific data points from HTTP headers, meta tags, or HTML content.
- Filter Field Values: Applying complex filters on the URL, Title, or other attributes to narrow down the scope of the crawl or analysis.
- Custom Value Tags (Advanced): Using regex to preprocess data before it’s displayed or saved.
Understanding the context of the field you are operating on is crucial for successful regex implementation.
🚀 Core Concepts of Regular Expressions
Before diving into examples, a quick refresher on essential regex components will prove invaluable:
*: Matches the preceding element zero or more times (e.g.,a*matches “”, “a”, “aa”, “aaa”).+: Matches the preceding element one or more times (e.g.,a+matches “a”, “aa”, but not “”).?: Makes the preceding element optional (zero or one time) (e.g.,colou?rmatches “color” or “colour”).[]: Character sets, matching any single character within the brackets (e.g.,[a-z]matches any lowercase letter).(): Grouping, allowing you to apply quantifiers to a group (e.g.,(apple|orange)matches either “apple” or “orange”).\(Backslash): Used to escape special characters that have regex meaning (e.g.,\.matches a literal dot, not ‘any character’).
🔗 Advanced Regex Use Cases for Link Analysis
Here are detailed, actionable scenarios for using advanced regex in your link audits.
1. Extracting Specific Parameterized URLs (The Clean-Up Regex)
Often, your site uses tracking parameters (e.g., utm_source, sessionid, ?ref=...) that pollute your primary crawl data. You need to analyze the clean, canonical URL.
The Goal: Strip all query parameters from the URL while preserving the base path.
The Regex Strategy: Use a pattern that matches and captures everything before the first ? or the end of the string.
Regex Example (Used in a custom field or transformation):
regex
^([^?]*)\?.*$|^([^?]*)$
Explanation:
* ^: Start of the string.
* ([^?]*): Capture Group 1. Matches any character that is not a ?, zero or more times.
* \?.*: Matches the literal ? followed by any characters until the end of the line (the junk parameters).
* |: OR condition.
* ^([^?]*)$: Capture Group 2. Catches the clean URL if no parameters are present.
Action: If the result of this regex is captured in Group 1, it’s your canonical URL path. This is crucial for accurately counting unique pages.
2. Identifying Specific Content Structures (The Selector Regex)
Sometimes you want to find links that follow a highly specific internal structure, such as product slugs that always contain a category code.
The Goal: Find all internal links that start with /products/ followed by an alphanumeric code and a slug, such as /products/cat-abc-xyz.
The Regex Strategy: Define the mandatory starting characters and the required structure.
Regex Example (Used in filtering/scraping links):
regex
/products/[a-z]{3}-[a-z]{3}-[a-z]{3}
Explanation:
* /products/: Matches the literal starting path.
* [a-z]{3}: Matches exactly three lowercase letters.
* -: Matches the literal hyphen.
* The pattern repeats this structure three times, ensuring the link follows the desired format (e.g., cat-abc-def).
Action: This helps isolate high-value, structured content links that might otherwise be lost in a general crawl.
3. Extracting Link Attributes (The Data Extraction Regex)
While Screaming Frog is great at finding href links, advanced regex can be used to pull data from non-standard elements or attributes.
The Goal: Extract all data-product-sku values from an element, regardless of how many times it appears on the page.
The Regex Strategy: Target the attribute name and use capturing groups to pull out the value.
Regex Example (Used in custom scraping/extraction):
regex
data-product-sku=["']([^"']+)["']
Explanation:
* data-product-sku= : Matches the literal attribute name.
* ["']: Matches either a double quote or a single quote (handling different HTML standards).
* (…): Capture Group 1.
* [^"']+: Matches one or more characters that are not a quote (the actual SKU value).
* ["']: Closes the attribute value match.
Action: This is indispensable when auditing e-commerce sites or complex single-page applications (SPAs) where product identifiers are stored in data attributes.
4. Filtering Out Non-Canonical URLs (The Exclusion Regex)
If your site has many non-preferred URLs (e.g., temporary staging links, resource directories, or specific query strings used by analytics), you need to filter them out during analysis.
The Goal: Exclude all URLs that contain common internal resource paths like /wp-admin/, /wp-includes/, or ?s=.
The Regex Strategy: Combine multiple OR conditions using the regex |.
Regex Example (Used in the URL field filter):
regex
(wp-admin|wp-includes|feed|s=|\/robots\.txt)
Explanation:
* (): Groups the alternatives.
* |: Acts as the OR separator.
* wp-admin: Matches the literal directory.
Action: By filtering for URLs not matching this pattern, you ensure your link analysis focuses only on user-facing, indexable content.
✅ Best Practices for Regex in Link Analysis
- Test, Test, Test: Never run a complex regex on a massive crawl dataset immediately. Test your pattern on a small, representative sample of your crawl data first.
- Be Specific: The more specific your regex, the better the results. Instead of
[a-zA-Z0-9], use[a-z]{3}if you know the structure must be three lowercase letters. - Understand Capture Groups: If you are using regex to extract data, always remember that the data you actually want is usually in a capture group
(), not the entire match. - Prioritize Safety: When in doubt, use the broader filtering in Screaming Frog’s Crawl settings (e.g., excluding directory paths) before relying on regex extraction.
Mastering regex in Screaming Frog transforms a tedious manual audit into an efficient, powerful data science exercise, giving you unparalleled control over the precision of your link analysis.