2

I am trying to replace ',",\ characters with blank.

I use the following code

jQuery.get('/path to file/file.txt',function(data){
  data = data.replace(/\'\"\\/g," ");
  alert(data);
})

but nothing replaced.

Where am I wrong?

2 Answers 2

1

Your expression would replace the 3 character sequence '"\ with a space, not the individual chars \, ' and ". Enclose them in a character class [] (and there's no need to escape with \ except for the \).

data = data.replace(/['"\\]/g," ");

// Example:
var str = "This string has internal \" double \\ quotes \\ and 'some single ones' and a couple of backslashes";
str = str.replace(/['"\\]/g," ");
// Output: all quotes replaced with spaces:
// "This string has internal   double   quotes   and  some single ones  and a couple of backslashes"
Sign up to request clarification or add additional context in comments.

1 Comment

Except for the slash, which does need to be escaped (as OP had in the question, \\ )
1

you are wrong. there is nothing to replace. regex does not open any file. all it does is replacing the char combination '" with whitespace.

what you search for is ['"] instead of \'\"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.