# Return last numbers of a variable length string

#### maounde

##### New Member
I am at a loss here. I have a collection of urls like this:
http://mycompany.com/t5/something/bd-p/153 (I need the formula to return 153)
or
http://mycompany.com/t5/something-else/bd-p/52 (I need the formula to return 52 )

Problems I find:
- The length in characters of the urls are variable
- The numbers at the end could be 2 to 4 digits

The only reliable constant I have is that the number I need to extract at the end is always after the last "/" and there are always exactly 6 "/", if it helps.

### Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

#### NeonRedSharpie

##### Well-known Member
Code:
``=RIGHT(RIGHT(A1,5),LEN(RIGHT(A1,5))-FIND("/",RIGHT(A1,5)))``

You said it's always AT MOST 4 digits. So just truncate that bad boy to 5 and then run your logic on that. Otherwise you could go through and start at the 6th "/" but that's a longer code.

#### barry houdini

##### MrExcel MVP
Try this formula

=LOOKUP(10^4,RIGHT(A1,{1,2,3,4})+0)

#### maounde

##### New Member
Wow... Both formulas work great. I am more familiar with the syntax of the first. The lookup one, with ^ and {}, not so much... but never mind, it works!
Thank you both!

#### István Hirsch

##### Well-known Member
If you do not want to use a formula, just replace */ with nothing.

Replies
4
Views
63
Replies
2
Views
92
Replies
4
Views
57
Replies
0
Views
113
Replies
4
Views
325