Solved

How to replace only explicit captures

Posted on 2007-03-30
3
193 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
[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
3 Comments
 
LVL 63

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 63

Expert Comment

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

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

690 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