我有一个字符串“IX - Delivery Received 1/15/2018 9:34:00 AM”我希望JavaScript中的字符串如“IX - Delivery Received”。
我很喜欢
var finalname = title.replace(/[0-9]/g, '');
var specialchar = finalname.replace(/[^A-Z0-9]/ig, "");
不能按预期工作。实际上我想在字符串包含第一个数字时修剪。可以请你指点!!
答案 0 :(得分:5)
可能在第一个号码上拆分/加入:
let str = "IX - Delivery Received 1/15/2018 9:34:00 AM ";
let out = str.split(/\d/, 1).join().trim();
console.log(out);

答案 1 :(得分:3)
你可以试试这个,
var title = "IX - Delivery Received 1/15/2018 9:34:00 AM ";
var digit = title.search(/\d/);
var finalname = title.substring(0, digit);
哪个输出“IX - 交付收到”