Solved

How to replace only explicit captures

Posted on 2007-03-30
3
182 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now