Tip - Find / Replace with RegEx Capture Groups

Find / replace with regular expression capture groups can be very powerful.

I needed to do a find replace that reused a portion of the find string in the replace - more clear in the following example:
Find:
<A target="_blank" HREF="(any link)">
Replace with:
<A target="_blank" HREF="(link found above)"><input type="checkbox" value="(link found above)" name="LinkList">

This isn't a simple find replace scenario, since I needed to reference the link twice in the replacement string. I wrote a macro to do this, but there were hundreds of occurrences and the macro was very slow. It turns out that the regex find / replace in VS.NET is perfect for this

Find criteria:
HREF={:q}\>
Replace string:
HREF=\1\>\<input type=checkbox value=\1 name=killList\>

The curly braces around the :q tells it to take the quoted string (:q) and put it in a variable. Then you can refer to that variable in the find or replace string as \1. If you use more than one {} group, it will go into \2, \3, etc.

[Listening to: La fredda lama del coltello - Ennio Morricone ]

Published Saturday, May 24, 2003 12:45 AM by Jon Galloway
Filed under:

Comments

# Good site

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=205 ">buy celebrex</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=202 ">buy bontril</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=203 ">buy buspar</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=204 ">buy carisoprodol</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=198 ">buy allegra</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=196 ">buy adipex</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=197 ">buy rogaine</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=199 ">buy alprazolam</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=200 ">buy ambien</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=215 ">buy deltasone</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=214 ">buy danazol</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=213 ">buy cozaar</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=212 ">buy condylox</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=211 ">buy codeine</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=210 ">buy claritin</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=209 ">buy cipro</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=201 ">buy aristocort</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=208 ">buy cialis</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=207 ">buy cialis online</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=206 ">buy celexa</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=222 ">buy evista</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=221 ">buy ephedra</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=220 ">buy echinacea</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=219 ">buy diflucan</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=218 ">buy didrex</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=217 ">buy diazepam</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=216 ">buy desyrel</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=229 ">buy lasix</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=228 ">buy ionamin</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=227 ">buy hydrocodone</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=226 ">buy fosamax</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=225 ">buy flexeril</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=224 ">buy fioricet</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=223 ">buy famvir</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=235 ">buy mesterolone</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=234 ">buy meridia</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=233 ">buy lortab</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=232 ">buy lorazepam</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=231 ">buy lipitor</a>

<a href=" http://nsstc.uah.edu/cgi-bin/enote112.pl?nb=notebook&action=view&page=230 ">buy levitra</a>

Thursday, May 10, 2007 4:09 AM by Opadokil

# Visual Studio Find (and Replace) Regular Expressions | Aaron Lerch

Pingback from  Visual Studio Find (and Replace) Regular Expressions | Aaron Lerch

# re: Tip - Find / Replace with RegEx Capture Groups

Do you want to see good pics?,

Sunday, June 15, 2008 1:39 PM by Edtcgook

# Tip - Find / Replace with RegEx Capture Groups in Visual Studio

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Monday, July 21, 2008 8:52 AM by DotNetKicks.com

# re: Tip - Find / Replace with RegEx Capture Groups

Best  all about gas powered scooters

www.world66.com/.../gas_powered_scoote

Wednesday, June 10, 2009 7:44 PM by gas powered scooters

# re: Tip - Find / Replace with RegEx Capture Groups

I bookmarked this guestbook.,

Wednesday, July 29, 2009 3:36 PM by name

# note-在VisualStudio中使用正则表达式

前言:本来昨天已经写了,但由于意外给搞丢失了,由于刚刚看了这篇文章知道了一些真相;现在的心理状态已经和昨天不一样了,昨天是满心的高兴,对VisualSduio很有好感,当时自认为是没有把正则学好,所以...

Tuesday, August 04, 2009 11:27 PM by qinghao

Leave a Comment

(required) 
(required) 
(optional)
(required)