Solved

Help with regular expression

Posted on 2007-04-01
4
174 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
Comment Utility
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
Comment Utility
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
Comment Utility
you could just do this:
string test = @"\root\sub1\sub2";
test =  test.Replace(@"\", @"--\\++" ).Substring(2) + "--";
0
 

Author Comment

by:brettr
Comment Utility
Very clean KarinLoos.  Thanks.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now