Reputation: 319
I am having issues with a regex for server paths. I have many paths and they can differentiate like:
\\server1\folder\file
or
\\server2\folder\subfolder\file
I need to get the server name out of it and only the server name. I have tried using
[\\(.*?)\\]
which gets the inverse of what I want and multiple parts rather than just the server name. What is the proper expression?
Upvotes: 1
Views: 457
Reputation: 13674
This regex matches everything between the \\
and the first \
:
(?<=\\\\)[^\\]*
Explanation
(?<=\\\\)
- starts with double \
[^\\]*
- matches any character except \
Upvotes: 3