Solved

How to replace only explicit captures

Posted on 2007-03-30
3
188 Views
Last Modified: 2013-11-06
I am using the following regEx expression to replace a word in an xml document
XML = Regex.Replace(XML, "(xsi:type="")(?<Replace>\w+)", "NEW TEXT", RegexOptions.ExplicitCapture)
When I run it on this text
<PMPComboBox xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="PMPComboBox">
it returns
<PMPComboBox xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" NEW TEXT">

Eventhough I have it set to ExplicitCapture which as I understand should ignore any unnamed caputre.

Could someone help me correct this RegEx string to replace appropriately
0
Comment
Question by:Corey2
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 18824129
Hi Corey2;

According to the documentation the Regex.Replace does the following, "Replaces all occurrences of a character pattern defined by a regular expression with a specified replacement character string.", this is without exception. Therefore to correct the Replacement pattern do the following:

XML = Regex.Replace(XML, "(xsi:type="")(?<Replace>\w+)", "$1NEW TEXT")

This will give you what you need.

Fernando

0
 
LVL 13

Author Comment

by:Corey2
ID: 18824921
I get it now. thanks
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 18826381
Not a problem, glad I was able to help. ;=)
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

777 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