0

When i have string which consists of a single line, replace works just fine.

As soon as i type in some text into text area and press enter as for new line, replace won't work anymore.

var currentValue = $('#service-field').val();
$('#service-field').val(currentValue.replace("particular string",""));

What should I do?

Blazemonger
  • 82,329
  • 24
  • 132
  • 176
Parthanaux
  • 135
  • 1
  • 14
  • you should take into account that the string might have a linebreak in it. – Kevin B Aug 15 '13 at 18:51
  • 1
    yep, you might also be interested by this post, http://stackoverflow.com/questions/1068280/javascript-regex-multiline-flag-doesnt-work – just_a_dude Aug 15 '13 at 18:52

1 Answers1

1

Try this to make sure you capture all occurrences, and not just the ones on the first line:

$('#service-field').val(currentValue.replace(/particular string/g, ""));

Or with a variable:

var t = "particular string";
$('#service-field').val(currentValue.replace(eval("/" + t + "/g"), ""));
Yuck
  • 44,893
  • 13
  • 100
  • 132