Home  >  Article  >  Web Front-end  >  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

WBOY
WBOYOriginal
2016-05-16 17:11:401743browse

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