Solved

Help with regular expression

Posted on 2007-04-01
4
180 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still 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…

729 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