HomeRedaction Guides → Redact Credit Cards

How to Redact Credit Card Numbers in a PDF

Use precise patterns to remove card numbers (including spaced or dashed formats), then verify the export to ensure the underlying text is gone.

Important: PermanentRedaction permanently removes text from text-based PDFs. Scanned/image-only PDFs are not supported.
Quick notes
Tip: Many PDF editors can only mask text with black rectangles. Masking is not the same as permanently deleting text from the PDF layer.

Step-by-step

Step 1
Identify how card numbers appear (spaces, dashes, or continuous digits).
See Example: Common formatting variants
Regex
\b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b
Matches
  • 4111 1111 1111 1111
  • 4111-1111-1111-1111
  • 4111111111111111
This targets 16-digit formats. Some cards use 13–19 digits; tighten/expand based on what you see in your PDFs.
Using regex rules in PermanentRedaction
PermanentRedaction supports deterministic redaction rules using regular expressions. Patterns like this can be applied across an entire document to permanently remove matching text.
Step 2
Create a targeted regex rule for the formats you see (avoid overly-broad patterns that match invoices/IDs).
Step 3
Preview matches and confirm you are only capturing card numbers (not unrelated long numbers).
Step 4
Export a final PDF where matched card numbers are permanently removed.
Step 5
Verify by searching/copying card number strings in the exported PDF and reviewing the verification report.

Common mistakes to avoid

Over-broad digit regex
Avoid patterns that match any long digit sequence—those can remove invoice IDs, case numbers, or unrelated references.
Only masking with black boxes
Masking is not deletion. If the underlying text remains, it can sometimes be copied, searched, or extracted.
Missing alternate formats
Card numbers may appear in multiple formats across pages (spaced, dashed, or wrapped). Add rules accordingly.
Skipping verification
Always verify the exported PDF, especially before filing or sending externally.

FAQ

Can I redact only the middle digits and keep the last 4?
Yes. Create rules that target only the portion you need removed, based on your policy.
Will this keep the PDF searchable?
Yes, if you use a text-preserving export and your workflow allows it.
What if the PDF is scanned?
Scanned/image-only PDFs are not supported in PermanentRedaction at this time.