1

I have an RTF string that contains \*\revtbl{Unknown;}}, it is used to indecate that the word that follows is misspelled (I think) and I need to remove it, when I do:

.replace(/{\*\revtbl{Unknown;}}/g, "")

I get two lines:

*
evtbl{Unknown;}}

When I change to:

.replace(/{\*\r|evtbl{Unknown;}}/g, "")

I get just the * and a second line. e.g.:

var tt = '\*\revtbl{Unknown;}}';
tt=tt.replace(/{\*\r|evtbl{Unknown;}}/g, "");
alert('"'+tt+'"');

I see:

"*
"

I could not find any reference about the use of the pipe | character so I need to know: if by using it am I asking to replace two separate strings one being {\*\r and the other being evtbl{Unknown;}} bottom line I need to replace the literal string \*\revtbl{Unknown;}} with nothing.

1 Answer 1

1

I think it is just a matter of escaping all the characters correctly

//sample string - NOTE: the backslashes had to be escaped for JS
var str = "RTF string that contains \\*\\revtbl{Unknown;}}, it is used to indecate that the word that follows is misspelled (I think) and I need to remove it, when I do:";

var regEx = /\\\*\\revtbl\{Unknown;\}\}/g;

console.log(str.replace(regEx, ''));
Sign up to request clarification or add additional context in comments.

10 Comments

Thank you for your reply, when I do tt = '\\*\\revtbl{Unknown;}}'; as you have done this works, however, the actual "literal" string is \*\revtbl{Unknown;}}. The RTF is imported, not entered so I cannot change it - thanks.
Is the literal string hard coded into your JS as a string or is it coming from a variable? If the value is just hard coded as a string you have to escape the backslash. For example if you do: console.log('\*\\revtbl{Unknown;}}') you will see that you aren't getting the double slashes
It's in a variable that is loaded from an xml file, so it is "literally", "exactly", "specifically" \*\revtbl{Unknown;}} - thanks.
It does not work, please show me how - thanks. I have t='{\*\revtbl{Unknown;}}' how do I remove it - thanks.
If that is what the string is going to be when loaded from your file, then you would want to use: var regEx = /\{*\revtbl\{Unknown;\}\}/g;
|

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.