Avatar of Andreas Hermle
Andreas Hermle
Flag for Germany asked on

extract a substring between backslashes from paths

Dear Experts:

I would like to extract the 'PM_xx' substrings, i.e. PM_4, PM_6 and PM_2_3 from the below Paths, using a formula if possible

The links have one thing in common.
Looking from the right: these are the substrings between the first and second backslash.


Help is much appreciated. Thank you very much in advance.

I have attached a sample file for your convenience.

Regards, Andreas

VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Subodh Tiwari (Neeraj)

8/22/2022 - Mon


pls try this UDF
Function CellRegexSimple(Myrange As String) As String
      Dim regex As Object
      Set regex = CreateObject("VBScript.RegExp")
      Dim strInput As String

        strInput = Myrange
        With regex
            .Global = True
            .MultiLine = True
            .IgnoreCase = False
            .Pattern = "\\(PM[\d_]*?)\\"
        End With
        On Error Resume Next
        Set Matches = regex.Execute(strInput)
        strRes = Matches(0).submatches(0)
        On Error GoTo 0
        CellRegexSimple = strRes
      Set regex = Nothing
End Function

Open in new window


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Andreas Hermle

Oh great Rgonzo, how quick you came up with this and it works just fine. Thank you very much for it.

If you do not mind, I will wait some more time, maybe some expert or you also come up with a formula approach.

Anyhow, a real superb job from your side. I really appreciate it. Regards, andreas
Andreas Hermle

uppps, here we are, our posts crossed, will test it right away ... :-)
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

Edited (a bit more precise)
Subodh Tiwari (Neeraj)

You may also try this....
Assuming your string is in A2 then


Open in new window

Andreas Hermle

Hi Rgonzo, I am really deeply impressed, how come you come up so fast with all these solutions. It is really incredible, I just do not get it :-)

A great job from your side, as always. Thank you very much for your professional help. I really appreciate it.

Regards, Andreas
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

@Neeraj the PM Folder is not allways  at the same level
Andreas Hermle

Upps, Subodh's and Rgonzo's post have crossed my post. I have already awarded the points. Subodh: will test your code and then let you know. Thank you very much for your great help.

Subodh Tiwari (Neeraj)

It's okay Andreas. :)
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes