javascript - Regex for both newline and backslash for Replace function -
i using replace function escape characters (both newline , backslash) string.
here code:
var str = strelement.replace(/\\/\n/g, "");
i trying use regex, can add more special characters if needed. valid regex or can tell me doing wrong here?
you're ending regex unescaped forward slash. want use set match individual characters. additionally might want add "\r" (carriage return) in "\n" (new line).
this should work:
var str = strelement.replace(/[\\\n\r]/g, "");
Comments
Post a Comment