Skip to content
Advertisement

Get selected characters from a url [closed]

I need to retrive a selected part from a url . I’ve used substr method and i’ve successfully get the character. But my issue is that ,this is my sample url localhost/xxxxxxx/sugar_daddy_member-1.xml i need to retrive the last number in the url. By using this below given code i can sucessfully get the number but if two digit number comes in the url i can retrive only one number.

JavaScript

Advertisement

Answer

You can use the strrpos function to find the dash.

JavaScript

Output

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement