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

escape Escape text for regex, shell, SQL, or JSON

{ } Encode
Input0 chars
Output0 chars

Flags

--mode select: regex | shell | sql | json-string default: regex

Examples

Escape special regex characters in a search string

Usage
"price is $9.99 (USD)" | escape

Escape a string for safe use in a shell command

Usage
"Hello, it's a 'wonderful' world!" | escape --mode=shell

Escape single quotes for a SQL query value

Usage
"O'Brien's order #42" | escape --mode=sql
View source
(input, opts = {})=>{
                switch(opts.mode || "regex"){
                    case "regex":
                        return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
                    case "shell":
                        return "'" + input.replace(/'/g, "'\\''") + "'";
                    case "sql":
                        return input.replace(/'/g, "''");
                    case "json-string":
                        return JSON.stringify(input).slice(1, -1);
                    default:
                        return input;
                }
            }