pipr.tools
Pipes
Clean Email Strip formatting from pasted email for clean plain text Clean AI Output Clean plain text from ChatGPT or AI output Decode & Format JWT Decode a JWT and pretty-print header and payload Word Frequency Count word frequency in text

regex-replace Replace text matching a regex pattern

.* Regex
Input0 chars
Output0 chars

Flags

--pattern string default:
--replacement string default:

Examples

Redact email addresses in a document

Usage
"John Doe: [email protected]
Jane Smith: [email protected]" | regex-replace --pattern=[\w.]+@[\w.]+ --replacement=[REDACTED]

Mask credit card numbers in a log file

Usage
"Card: 4532-1234-5678-9012
Backup: 4532-9876-5432-1098" | regex-replace --pattern=\d{4}-\d{4}-\d{4} --replacement=****-****-****

Replace multiple spaces with single spaces in pasted text

Usage
"Too  many   double   spaces  in  this   text." | regex-replace --pattern= {2,} --replacement= 
View source
(input, opts = {})=>{
                if (!opts.pattern) return "Error: provide --pattern";
                try {
                    return input.replace(new RegExp(opts.pattern, "gm"), opts.replacement || "");
                } catch (e) {
                    return `Error: ${e.message}`;
                }
            }

Also useful for

Related Tools