473,467 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Regular Expression: replace method

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
Jul 19 '05 #1
1 1639
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" <ne***************************@seamlyne.com> wrote in
message news:c2*************@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

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Keith Morris | last post by:
Hi all! I'm creating a mini CMS that will store content in a MySQL database. What I am trying to do is parse the content and replace certain keywords with a link. The keywords and associated...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
7
by: MichaelPyles | last post by:
Using IIS 5.1, XP, dev studio 2003, ASP I've discovered an insidious bug with the VBScript Regular Expression object. I set the pattern to consist of the set of invalid filename characters plus...
9
by: Harry | last post by:
Hi there, does anyone know how I can build a regular expression e.g. for the string.search() function on runtime, depending on the content of variables? Should be something like this: var...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
2
by: Brian Kitt | last post by:
I have a process where I do some minimal reformating on a TAB delimited document to prepare for DTS load. This process has been running fine, but I recently made a change. I have a Full Text...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
3
by: TOXiC | last post by:
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it...
1
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "":...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.