0

I'm having difficulties changing an error message in this app using Spring.

If the user enters in the wrong account a custom message (that I can't edit) fires.
I need to replace [BR][BR] (coming from netBiscuits) with an empty string('');

The error message is from a message.properties file if I need to I will post that as well.

Here's my code:

var text = "[BR]''[BR]";
var data = st(text);
replace(data);

function st(ip) 
{
    var str = ip;
    return str.replaceWith(/[.*?]/g,"");
}

This is not my original code, but the replace(data) is a spin-off a test I was running with an alert box because after about 8 hours, I'm still stuck.

Nope
  • 22,147
  • 7
  • 47
  • 72
Abraxas
  • 374
  • 3
  • 10
  • `text` is a string. [`replaceWith`](http://api.jquery.com/replaceWith/) is a jQuery method, not a string method. – jbabey Dec 21 '12 at 19:37

1 Answers1

2

For strings, use the standard replace function :

 return str.replace(/[.*?]/g,"");

JQuerys replaceWith is used to replace elements.

But, even if I'm not sure of your exact goal, I think your regex doesn't do what you want.

You probably should escape the [ and ] :

return str.replace(/\[.*?\]/g,"");
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • Thanks dystroy! Ok so before we go further with this I actually replaced the code and put it back into an alert box to show var text = ('[BR][BR]',''); var data = st(text); alert(data); function st(ip) { var str = ip; return str.replace(/[](.*)>/g,''); } ...this is giving me a better result by taking out the biscuits tags in the alertbox. Now how do I remove it from my jsp? – Abraxas Dec 21 '12 at 19:18