Talk:Regular Expressions Tutorial

Return to "Regular Expressions Tutorial" page.

Using RegEx to save programming time on VB6 code

I have a list of forms:

frInterface(0) frInterface(1) pboxTrack txtOut pbar2 pbar1 lbWait lb0msTop lb100msTop lb50msTop lb100msBottom lb500msBottom lb1000msBottom lbStatus txtNull

I need to use them to make formulas and new variables. It would take a lot of time to manually type it all. Using a Windowz application search and replace will not do any good. RegEx to the rescue!

%s/^\(.*\)/mw\1 = \1.width \/ me.width:  mh\1 = \1.height \/ me.height/

Yields:

mwfrInterface(0) = frInterface(0).width / me.width:  mhfrInterface(0) = frInterface(0).height / me.height
mwfrInterface(1) = frInterface(1).width / me.width:  mhfrInterface(1) = frInterface(1).height / me.height
mwpboxTrack = pboxTrack.width / me.width:  mhpboxTrack = pboxTrack.height / me.height
mwfrInterface = frInterface.width / me.width:  mhfrInterface = frInterface.height / me.height
mwtxtOut = txtOut.width / me.width:  mhtxtOut = txtOut.height / me.height
mwpbar2 = pbar2.width / me.width:  mhpbar2 = pbar2.height / me.height
mwpbar1 = pbar1.width / me.width:  mhpbar1 = pbar1.height / me.height
mwlbWait = lbWait.width / me.width:  mhlbWait = lbWait.height / me.height
mwlb0msTop = lb0msTop.width / me.width:  mhlb0msTop = lb0msTop.height / me.height
mwlb100msTop = lb100msTop.width / me.width:  mhlb100msTop = lb100msTop.height / me.height
mwlb50msTop = lb50msTop.width / me.width:  mhlb50msTop = lb50msTop.height / me.height
mwlb100msBottom = lb100msBottom.width / me.width:  mhlb100msBottom = lb100msBottom.height / me.height
mwlb500msBottom = lb500msBottom.width / me.width:  mhlb500msBottom = lb500msBottom.height / me.height
mwlb1000msBottom = lb1000msBottom.width / me.width:  mhlb1000msBottom = lb1000msBottom.height / me.height
mwlbStatus = lbStatus.width / me.width:  mhlbStatus = lbStatus.height / me.height
mwtxtNull = txtNull.width / me.width:  mhtxtNull = txtNull.height / me.height

Now I need to declare the variables. More nasty manual edits? nope. RegEx makes it fast and easy!

%s/^\(.*\)/dim mw\1 as single, mh\1 as single/

Yields:

dim mwfrInterface(1) as single, mhfrInterface(1) as single
dim mwpboxTrack as single, mhpboxTrack as single
dim mwtxtOut as single, mhtxtOut as single
dim mwpbar2 as single, mhpbar2 as single
dim mwpbar1 as single, mhpbar1 as single
dim mwlbWait as single, mhlbWait as single
dim mwlb0msTop as single, mhlb0msTop as single
dim mwlb100msTop as single, mhlb100msTop as single
dim mwlb50msTop as single, mhlb50msTop as single
dim mwlb100msBottom as single, mhlb100msBottom as single
dim mwlb500msBottom as single, mhlb500msBottom as single
dim mwlb1000msBottom as single, mhlb1000msBottom as single
dim mwlbStatus as single, mhlbStatus as single
dim mwtxtNull as single, mhtxtNull as single
Last modified on 9 February 2008, at 10:22