Connecting Tech Pros Worldwide Forums | Help | Site Map

How to omit replacement in somepart of text using regular expression?

Newbie
 
Join Date: Sep 2008
Posts: 17
#1: Nov 7 '08
How to omit replacement in somepart of text using regular expression?

For ex:

If i want to replace mumbai with mumbai/aaa.com but if i have an anchor tag

<a href="/mumbai/bbb.com>mumbai</a>
then in the anchor tag too the replacement takes place which should not be done..

How to solve this problem?

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Nov 7 '08

re: How to omit replacement in somepart of text using regular expression?


Post the code you have used for the replacement.
Newbie
 
Join Date: Sep 2008
Posts: 17
#3: Nov 7 '08

re: How to omit replacement in somepart of text using regular expression?


Regex.Replace(str1, m.Result("$2"), sRep);


str1 is the htm file where the string is to get modified and srep is the string that replaces ..
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Nov 7 '08

re: How to omit replacement in somepart of text using regular expression?


See the specs for the Replace . There are overloads that allow you to specify how many times the replacement can occur.
Newbie
 
Join Date: Sep 2008
Posts: 17
#5: Nov 7 '08

re: How to omit replacement in somepart of text using regular expression?


Quote:

Originally Posted by padmaneha

Regex.Replace(str1, m.Result("$2"), sRep);


str1 is the htm file where the string is to get modified and srep is the string that replaces ..


can u please write a code for example?
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#6: Nov 7 '08

re: How to omit replacement in somepart of text using regular expression?


The code examples are there in the specs for that method. It's just a matter of picking the correct Replace method from the class which also accepts an integer specifying the number of replacements to do.
Reply