need a c# regex to get servername out of UNC -


I see my last post spoiled that I can get this one right ..

Can anyone tell me how to remove the name of the server from the UNC? (I'm looking for a regex)

This is the string that I want to draw the server name from:

  ** \\\ servername \ d $ \ Directory * *  

My code is in C #

  Regex r = New Regex (?????, RegexOptions.IgnoreCase); Match Me = R. Match (@ "\\ servername \ d $ \ directory"); CaptureCollection cc = m.Captures; Front (Capture C in CC) {System.Console.WriteLine (c); }  

I'm just looking to capture: servername

no slash or nothing.

Note: This answer is for educational purposes - it is better to use Uri object and Does not reuse existing functions.

In the form of the same solution, but reversed with backslashes, and therefore escaped, (and removed proprietary xxfire, since C # regex does not support):

  (? & Lt; = ^ \\\\) [^ \\] +  


Name of the server \ 0 or $ 0 or simply the result of the function, how do you say it and what do C # offer?


explanation in regex comment mode:

  (? X) # to enable flag regex annotations (? & Lt; = # start-up looks positive ^ # Beginning line \\\\ # Backspace is left to give the literal \\ character.) # Finally look positive [^ \\] + # Greed found the end of any non-string.  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -