Solved

Help with regular expression

Posted on 2007-04-01
4
177 Views
Last Modified: 2013-11-07
I have a string similar to this:

\root\sub1\sub2

I need it reformatted to this:

\\++root--\\++sub1--\\++sub2--

Using this only replaces the slash and original text: \\[a-z]*.  Howevr, I don't want to replace the original text.  How can I surround the original text like the above?
0
Comment
Question by:brettr
  • 2
4 Comments
 
LVL 10

Assisted Solution

by:Jaax
Jaax earned 50 total points
ID: 18834771
Why not use only '\\' as the search Regex ? Anyway even in the input, '\' cannot appear in the middle or at the end of the input.
0
 

Author Comment

by:brettr
ID: 18834796
Right - the slash will throw an exception.  I ended up using a simple Replace() and then removing unwanted characters from the beginning and appending wanted characters to the end.  It works fine.
0
 
LVL 13

Accepted Solution

by:
KarinLoos earned 450 total points
ID: 18834825
you could just do this:
string test = @"\root\sub1\sub2";
test =  test.Replace(@"\", @"--\\++" ).Substring(2) + "--";
0
 

Author Comment

by:brettr
ID: 18836173
Very clean KarinLoos.  Thanks.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question