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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -