Home > Article > Web Front-end > Three implementation methods of javascript intercepting the specified string from the right_javascript skills
Intercept the fg on the right side of abcdefg
Method 1
<script> <br>string="abcdefg" <br>alert(string.substring(string.length-2,string.length)) <br></script>
Method 2
<script> <br>alert("abcdefg".match(/.*(.{2})/)[1]) <br></script>
<script> <br>alert("abcdefg".match(/.{2}$/)) <br></script>
Method 3