我是jQuery中的新手。
我有一个像
的网址http://example.com/test/the-apartment/tomt-7-1-103-5-kvm-bra
我想剪切tomt-7
并删除-
。最终结果应为:tomt7
答案 0 :(得分:3)
这应该会给你想要的结果:
var str = "http://example.com/test/the-apartment/tomt-7-1-103-5-kvm-bra"
var last = str.split('/');
last = last[last.length -1];
var result = last.split('-').slice(0,2).join("");
<强>演示强>
var str = "http://example.com/test/the-apartment/tomt-7-1-103-5-kvm-bra"
var last = str.split('/');
last = last[last.length -1];
var result = last.split('-').slice(0,2).join("");
console.log(result)
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;