user3532863 user3532863 - 1 year ago 93
Javascript Question

How to replace date pattern in javascript string

How to remove a date patterns in a JavaScript string like below?
from "Mobile Phone 1/15/06" to "Mobile Phone"

var str ="Mobile Phone 1/15/06";

ccf ccf
Answer Source

You could use regex to match and replace the date pattern:

var str ="Mobile Phone 1/15/06";
var result = str.replace(/\s+\d{1,2}\/\d{2}\/\d{2}/g, '');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download