2

I have the following JavaScript:

var value = '19-JUL-10 04.36.38.643000 PM-->19-JUL-10 05.06.33.962000 PM' 

How can I use jQuery to trim it to become '19-JUL-10 04.36.38 PM-->19-JUL-10 05.06.33 PM'?

1 Answer 1

3

No need for jQuery, plain ol' JavaScript will do. Use a regular expression with the replace() method:

var value = '19-JUL-10 04.36.38.643000 PM-->19-JUL-10 05.06.33.962000 PM';
alert(value.replace(/\.\d{6}/g, ""));
//-> "19-JUL-10 04.36.38 PM-->19-JUL-10 05.06.33 PM"

The regular expression, /\.\d{6}/g, looks for a . immediately followed by and including 6 consecutive digits (\d{6}). The global switch (/g) is applied to make it replace all (both) occurrences.

1
  • 1
    i was going to suggest substr, but this is far more elegant Commented Aug 23, 2010 at 10:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.