Extract word that begins with the Nth specific character

garryhe

New Member
Joined
Sep 2, 2016
Messages
2
Hi Everyone!

I came across a problem that I need to extract all the text after the second last "/" in a link. For example:
"http://www.groupon.be/deals/antwerpen/hotel-kenzi-farah/30596211"
I need "hotel-kenzi-farah/30596211".

The total number of "/" is not constant, but what is certain is that the information after the second last "/" is all I need.

Really appreciate any help.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
=mid(a1;find("@*";substitute(a1;"/";"@*";len(a1)-len(substitute(a1;"/";""))-1);1)+1;len(a1))
 
Upvote 0
Shorter...

=REPLACE(A2,1,FIND("",SUBSTITUTE(A2,"/","",LEN(A2)-LEN(SUBSTITUTE(A2,"/",""))-1)),"")

Using the backslash symbol causes the above line: backslash between quotes becomes a blank! Likely a board software issue.

Rich (BB code):
=REPLACE(A2,1,FIND("\",SUBSTITUTE(A2,"/","\",LEN(A2)-LEN(SUBSTITUTE(A2,"/",""))-1)),"")

The backslash issue does not occur in between code tags...
 
Last edited:
Upvote 0
Hello garryhe,

paste the below function in Module1
Code:
Function ExtractText(ByVal s As Range) As String

Dim iFindSlash As Integer, i As Integer, p As Integer, m As Integer
Dim iPos() As Integer

' extract count of Slash
For p = 1 To Len(s)
    If Mid(s, p, 1) = "/" Then
        m = m + 1
        iFindSlash = iFindSlash + 1
      ReDim Preserve iPos(m)
            iPos(m) = p
    End If
Next p


For i = LBound(iPos) + 1 To UBound(iPos)
        
  If i = UBound(iPos) - 1 Then
       ExtractText = """" & Mid(s, iPos(i) + 1, 100)
       Exit Function
  End If
Next i


End Function

now try in excel
i.e.
Code:
=ExtractText(A1)
 
Upvote 0

Forum statistics

Threads
1,217,385
Messages
6,136,277
Members
450,001
Latest member
KWeekley08

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top