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!


--
William Morris
Product Development, Seritas LLC
Kansas City, Missouri

Re: Regular Expression: replace method by William

William
Wed Mar 03 12:03:22 CST 2004

Well, we've got the first problem solved, and introduced another.

TestString = "300 mdx 300"
Pattern = (\b|\d)MDX(?=\b|\d)
Success = 300 MDX 300

TestString = "300mdx 300"
Pattern = (\b|\d)MDX(?=\b|\d) << same as prev
Failed = 30MDX 300 << "30" instead of "300" at the beginning of the string.

TestString = "300mdx 300"
Pattern = (?!\b|\d)MDX(?=\b|\d)
Success = 300MDX 300

TestString = "300 mdx 300"
Pattern = (?!\b|\d)MDX(?=\b|\d) << same as prev
Failed = 300 mdx 300 << replace failed

Help!



"William Morris" <news.remove.this.and.the.dots@seamlyne.com> wrote in
message news:c252j9$1oc84a$1@ID-205671.news.uni-berlin.de...
> 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!
>
>
> --
> William Morris
> Product Development, Seritas LLC
> Kansas City, Missouri
>
>