Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All.
Really need some help here.
I need to replace the string between the second and third back slash. There will always be a second and third slash.

IncludeFiles = \\mckirlwebpd3srv\CDODFiles

Thanks in advance for any help given

What I have tried:

nothing tried so far as not sure where to start
Posted
Updated 27-Mar-18 23:51pm

 
Share this answer
 
Try:
VB
Imports System.Text.RegularExpressions
...
Public Dim regex As Regex = New Regex( _
      "(?<=\\\\).+(?=\\)", _
    RegexOptions.Multiline _
    Or RegexOptions.Singleline _
    Or RegexOptions.CultureInvariant _
    Or RegexOptions.Compiled _
    )
...
Dim result As String = regex.Replace(strInput,strReplacement)


Quote:

I'm new to Regex and I should have given the full string
IncludeFiles = \\mckirlwebpd3srv\CDODFiles\71669\ClaimReviewCustomizationGuideV61.pdf


Output I need is
IncludeFiles = p:\CDODFiles\71669\ClaimReviewCustomizationGuideV61.pdf
Ah! Change the regex string to:
VB
Public Dim regex As Regex = New Regex( _
      "\\\\.+(?=\\)", _
 
Share this answer
 
v2
Comments
johnjsm 28-Mar-18 6:06am    
The input string will be different form time to time so I will not know what the input string will be
OriginalGriff 28-Mar-18 6:23am    
That's ok - provided the bit you want to replace starts with "\\" and ends with "\" it will work: that's the whole idea of a regular expression. Try it and see!

If your input string doesn't always have that format, then you need to look at a whole load of examples of genuine inputs and find some "similarity" that can be used as a basis for checking - or no automatic system will work!
johnjsm 28-Mar-18 6:24am    
I'm new to Regex and I should have given the full string
IncludeFiles = \\mckirlwebpd3srv\CDODFiles\71669\ClaimReviewCustomizationGuideV61.pdf

Output I need is
IncludeFiles = p:\CDODFiles\71669\ClaimReviewCustomizationGuideV61.pdf
OriginalGriff 28-Mar-18 6:36am    
You need to be precise when you tell us things! :laugh:
See updated answer.
johnjsm 28-Mar-18 6:44am    
I guess i'm excited that today is my Friday and can't wait to get out of work.
I tried the update on the following

IncludeFiles = \\mckirlwebpd3srv\CDODFiles\71669\ClaimReviewCustomizationGuideV61.pdf

I get this output
\\mckirlwebpd3srv\CDODFiles\71669

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900