abcdefg
要求截取倒数两个字符,也就是“fg”.
以下是几种实现方式:
<script>
string="abcdefg"
alert(string.substring(string.length-2,string.length))
</script>
<script>
alert("abcdefg".match(/.*(.{2})/)[1])
</script>
<script>
alert("abcdefg".match(/.{2}$/))
</script>
<script>
alert("abcdefg".slice(-2))
</script>