Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如 21/10/2013.. 我想删除 /2013..
replace('/2013', '')工作,但日期可能是其他值,如 2014、2015 等
replace('/2013', '')
这将删除从最后/开始的所有内容:
/
var str = "21/10/2013"; var new_str = str.substring(0,str.lastIndexOf('/'));
尝试:
'21/10/2013'.replace(/\/\d+$/,''); // 21/10
这将删除最后一个“/”和字符串末尾之后的任何数字。