Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to replace only explicit captures

Posted on 2007-03-30
3
Medium Priority
?
197 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:Corey Scheich
[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 64

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:Corey Scheich
ID: 18824921
I get it now. thanks
0
 
LVL 64

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
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.

604 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