MCPcopy Index your code
hub / github.com/jprichardson/string.js / escapeRegExp

Function escapeRegExp

lib/string.js:818–841  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

816 };
817
818 function escapeRegExp (s) {
819 // most part from https://github.com/skulpt/skulpt/blob/ecaf75e69c2e539eff124b2ab45df0b01eaf2295/src/str.js#L242
820 var c;
821 var i;
822 var ret = [];
823 var re = /^[A-Za-z0-9]+$/;
824 s = ensureString(s);
825 for (i = 0; i < s.length; ++i) {
826 c = s.charAt(i);
827
828 if (re.test(c)) {
829 ret.push(c);
830 }
831 else {
832 if (c === "\\000") {
833 ret.push("\\000");
834 }
835 else {
836 ret.push("\\" + c);
837 }
838 }
839 }
840 return ret.join("");
841 }
842
843 function ensureString(string) {
844 return string == null ? '' : '' + string;

Callers 1

string.jsFile · 0.85

Calls 1

ensureStringFunction · 0.85

Tested by

no test coverage detected