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

Andreas HermleTeam leaderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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

Or pls try

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andreas HermleTeam leaderAuthor Commented:
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
Ensure Business Longevity with As-A-Service

Using the as-a-service approach for your business model allows you to grow your revenue stream with new practice areas, without forcing you to part ways with existing clients just because they don’t fit the mold of your new service offerings.

Andreas HermleTeam leaderAuthor Commented:
uppps, here we are, our posts crossed, will test it right away ... :-)
Edited (a bit more precise)
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may also try this....
Assuming your string is in A2 then


Open in new window

Andreas HermleTeam leaderAuthor Commented:
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
@Neeraj the PM Folder is not allways  at the same level
Andreas HermleTeam leaderAuthor Commented:
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)Excel & VBA ExpertCommented:
It's okay Andreas. :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.