473,569 Members | 2,984 Online
Bytes | Software Development & Data Engineering Community
+ 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 1646
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
2613
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 links are kept in a MySQL table. Here is an example. $keyword = "Widgets Technology Co."; $location = "http://www.widgets.com/about";
1
4157
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 regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) ...
7
2463
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 comma. I set global property to true then do a replace on a SID. The Replace does nothing. However, if I attach the C++ (dev studio 2003) debugger...
9
3143
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 strkey = "something"; var str = "Somethin like this"; if( str.search( / + strkey + / ) > -1 )
11
5359
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, I want to use the text included within the brackets to do a lookup so that I can replace the expression with the new text. For example:
3
3202
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 that this will one or more occurrences to replace all the white space between with a comma. This search ElseIf InStr(1, indivline, "$") Then insert...
2
3006
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 index on one column, and punctuation in the column was causing some problems down the line. This column is used only for full text indexing, and...
7
3802
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 want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way...
3
16910
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 with: import fileinput, string, sys fileQuery = "Text.txt" sourceText = '''SOURCE'''
1
3383
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 "": --------------------------------- myStringVar = myStringVar.replace("^" + iName + "=,($|&)", ""); --------------------------------- The following DOES replace it though:...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6290
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.