Home >Web Front-end >JS Tutorial >Three implementation methods of javascript intercepting the specified string from the right_javascript skills

Three implementation methods of javascript intercepting the specified string from the right_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 17:11:401795browse

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