?
Solved

How to replace only explicit captures

Posted on 2007-03-30
3
Medium Priority
?
195 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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 column That will then direct you to their download page. From that p…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 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