Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expression match value

Status
Not open for further replies.

iminore

Programmer
Sep 3, 2002
50
GB
look at this code:

set regx = new RegExp
regx.IgnoreCase = True
regx.Global = True
regx.Pattern = Sch
set reMatches = regx.Execute(DtlRow)
if reMatches.Count>0 then
for each objMatch in reMatches
DtlRow=regx.Replace(DtlRow,&quot;<b style='background- color:#AAAAFF;'>&quot; & objMatch.Value & &quot;</b>&quot;)
next
end if

so we are searching string DtlRow for occurrences of Sch

suppose DtlRow contains:
Practical and practical
and Sch is 'practical'
then the result is:
practical and practical
the regular expression finds both but the first gets changed to lowercase, like the second.
it seems the objMatch.Value stores the last value found.
?????


 
Try to play with objMatch.FirstIndex

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I don't see how the FirstIndex property helps.
 
In fact, as your RegExp is Global, the Replace method do the replacement for all matches each time it's called.
So the result is allways the last call.
I suggested FirstIndex (and the correlated Length property) to replace the regx.Replace call with some Mid function calls. (Tip: browse the Matches collection backward from end)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top