Created
September 8, 2014 18:44
-
-
Save shichao-an/f6b5961f153f061992cc to your computer and use it in GitHub Desktop.
Escape string for BRE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
escape() { | |
local raw="$1" | |
local quoted=$(printf %s "$raw" | sed 's/[][()\.^$?*+]/\\&/g') | |
echo "$quoted" | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment