TruffleHog Regexes

0.0.7 · active · verified Fri Apr 17

trufflehogregexes is a Python package that provides the core regular expressions used by the TruffleHog secrets scanner. It offers a structured list of dictionaries, each containing a regex pattern, ID, name, and tags for various sensitive information. Currently at version 0.0.7, it has a low release cadence, primarily serving as a data dependency for the main TruffleHog application.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to import and inspect the `regexes` list. It also shows a basic way to iterate and apply one of the regexes using Python's `re` module, as the package only provides the patterns, not the matching logic.

from trufflehogregexes import regexes

# The 'regexes' variable is a list of dictionaries
print(f"Total regexes available: {len(regexes)}")
if regexes:
    first_regex = regexes[0]
    print(f"\nExample regex entry:")
    print(f"  ID: {first_regex.get('id')}")
    print(f"  Name: {first_regex.get('name')}")
    print(f"  Regex: {first_regex.get('regex')}")
    print(f"  Tags: {first_regex.get('tags')}")

    # To actually use a regex, you'd compile and run it:
    import re
    test_string = "My private key is: AKIAIOSFODNN7EXAMPLE"
    for r_entry in regexes:
        pattern = r_entry.get('regex')
        if pattern:
            # Note: some regexes might require 're.DOTALL' or other flags
            match = re.search(pattern, test_string)
            if match:
                print(f"\nMatch found for '{r_entry.get('name')}': {match.group(0)}")
                break # Found one match for demonstration

view raw JSON →