Qook
Qook

Reputation: 33

Match part of a file path with regex

Using regex I need to extract part of a UNC path. Example:

I need to get the value after the share, so in this example i need to get:

The \server\share\ is always the same, but the number of subfolders can vary. I've tried different regex examples and working from those, but I just don't get it...

I've tried some regex with a regex tester, when I find a code where my result is in a group, I don't know how to use that specific group.

.*\\(\w\S+)\\(\w\S+) gives a subfolder, not what I need

Upvotes: 3

Views: 1149

Answers (1)

Pushpesh Kumar Rajwanshi
Pushpesh Kumar Rajwanshi

Reputation: 18357

Use this regex and capture your value from group1.

\bshare\\([^\\]+)

Here, \bshare matches share as exact word followed by \ and capture one or more characters other than \ what follows after.

Regex Demo

Upvotes: 1

Related Questions