W
William Morris
Been pounding on this for an hour and eating up my day's productivity, so I
thought I'd throw a question out there. (I'm also reading through the
Google archives to try to find this answer...)
Windows 2000 Small Business Server
Using regular expressions for the first time, and having difficulty with the
replace method. We're searching through a list of vehicle models, trying to
replace what we get from the client data with correctly propercased
text...ie..we get FORD F150 and replace it with Ford F150; CHEVROLET ES 300
and replace it with Chrevrolet ES 300; ACURA MDX >> Acura MDX. The usual
propercase algorithms don't work because of the multiple capitals in some of
the model names: we don't want Acura Mdx.
The test method always works. The problem we're having is that, under
certain circumstances, the replace method is replacing too much. We've
created a table of capitals as they relate to models: ES; MDX; XL; SL; and
so on. The pattern we're using is this:
\b varCapitals (\b|\d) << with spaces for clarity
which I read to mean "a word boundary followed by our capitals followed by
either a word boundary or a number."
And now a sample of our output, assuming a capital combination of "ES".
Shadowes >> Shadowes (good)
Shadow es >> Shadow ES (good)
es 300 >> ES 300 (good)
es300 >> ES00 (failed - we want ES300)
What needs to change in the pattern? Thanks for taking the time!
thought I'd throw a question out there. (I'm also reading through the
Google archives to try to find this answer...)
Windows 2000 Small Business Server
Using regular expressions for the first time, and having difficulty with the
replace method. We're searching through a list of vehicle models, trying to
replace what we get from the client data with correctly propercased
text...ie..we get FORD F150 and replace it with Ford F150; CHEVROLET ES 300
and replace it with Chrevrolet ES 300; ACURA MDX >> Acura MDX. The usual
propercase algorithms don't work because of the multiple capitals in some of
the model names: we don't want Acura Mdx.
The test method always works. The problem we're having is that, under
certain circumstances, the replace method is replacing too much. We've
created a table of capitals as they relate to models: ES; MDX; XL; SL; and
so on. The pattern we're using is this:
\b varCapitals (\b|\d) << with spaces for clarity
which I read to mean "a word boundary followed by our capitals followed by
either a word boundary or a number."
And now a sample of our output, assuming a capital combination of "ES".
Shadowes >> Shadowes (good)
Shadow es >> Shadow ES (good)
es 300 >> ES 300 (good)
es300 >> ES00 (failed - we want ES300)
What needs to change in the pattern? Thanks for taking the time!