Created
October 24, 2016 02:38
-
-
Save zmmbreeze/04ffd063f57a8c6a503fd742277b6303 to your computer and use it in GitHub Desktop.
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
function preg_quote( str ) { | |
// http://kevin.vanzonneveld.net | |
// + original by: booeyOH | |
// + improved by: Ates Goral (http://magnetiq.com) | |
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
// + bugfixed by: Onno Marsman | |
// * example 1: preg_quote("$40"); | |
// * returns 1: '\$40' | |
// * example 2: preg_quote("*RRRING* Hello?"); | |
// * returns 2: '\*RRRING\* Hello\?' | |
// * example 3: preg_quote("\\.+*?[^]$(){}=!<>|:"); | |
// * returns 3: '\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:' | |
return (str+'').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment