?
Solved

Help with regular expression

Posted on 2007-04-01
4
Medium Priority
?
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Assisted Solution

by:Jaax
Jaax earned 200 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 1800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Suggested Courses

801 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