ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old March 14th, 2008, 10:26 AM
nhrrdan nhrrdan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 61 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 19 m 22 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
Question RegEx Help

Hello All,
I've been away from the boards for a while, but I have a question about regular expressions. So if there is an expert in this area, I have a question for you.

I've created a label set (basically renamed words for different customer settings). To give you a better understanding, one client may choose to call their clients "distributors" while another may choose to call them "customers". I am also using these labels for language translation in some reports.

So my question is, I need to replace the text in a string with these custom labels.

Example:
"This is a tool test to show it works."

In this string I want to replace the word "to" with another string, lets say the word "and". But when I use the replace() function with the 'all' scope, it gives me this:

"This is a andol test and show it works."

I just want to change the word "to", not the beginning of the word "tool". This is the simplest of examples, but if I could find a way to search for whole words, rather than a substring, it would work great for me. I assume that regular expressions can do this somehow with the REReplace() function, I just don't know RegEx well enough to do this.

Any and all help will be greatly appreciated.

Thanks,
Dan

Reply With Quote
  #2  
Old March 14th, 2008, 01:55 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,475 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 7 m 51 sec
Reputation Power: 42
Try ReReplaceNoCase and the regex "\bto\b".
Comments on this post
nhrrdan agrees!
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old March 14th, 2008, 02:03 PM
nhrrdan nhrrdan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 61 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 19 m 22 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
Quote:
Originally Posted by kiteless
Try ReReplaceNoCase and the regex "\bto\b".


Once again kiteless, you provide a solution. Thank you, it worked like a charm.

Who knew it would be this simple though, I really need to study some regex.

Thanks,
Dan

Reply With Quote
  #4  
Old March 19th, 2008, 10:50 AM
nhrrdan nhrrdan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 61 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 19 m 22 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
This all worked great, but now it has expanded. I am actually manipulating an HTML dump that gets stored in a cfsavecontent variable. I now want to exclude any and all tags (i.e. Table, TR, TD, etc..., basically anything between '<' and '>') I also want to exclude anything between the <style> and </style> tags so the display does not get altered by accident, so ultimately I am just changing the static text that gets displayed to the client. Can this be done with RegEx, or do I have to employ some if/else funtionality to do what I need?

As always, any help is appreciated.

Thanks,
Dan

Reply With Quote
  #5  
Old March 19th, 2008, 11:42 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,475 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 7 m 51 sec
Reputation Power: 42

Reply With Quote
  #6  
Old March 19th, 2008, 12:19 PM
nhrrdan nhrrdan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 61 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 19 m 22 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
Quote:
Originally Posted by kiteless


Hi Kiteless, I actually already looked at that, but that function seems to actually strip the tags(you pointed me to cflib.org a while back and have used numerous functions from there).

I may be able to still use it to change all the tags, commit my own changes, and then change all the tags back. I want to keep the tags intact, so I will let you know how it goes.

Thanks again,
Dan

Reply With Quote
  #7  
Old March 19th, 2008, 12:43 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,475 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 7 m 51 sec
Reputation Power: 42
When you said "exclude the tags" I thought you meant remove them. The function will take a list of tags to exclude if that will work. What, exactly, are you trying to strip out?

Reply With Quote
  #8  
Old March 19th, 2008, 01:25 PM
nhrrdan nhrrdan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 61 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 19 m 22 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
Quote:
Originally Posted by kiteless
When you said "exclude the tags" I thought you meant remove them. The function will take a list of tags to exclude if that will work. What, exactly, are you trying to strip out?


Sorry, I should have said ignore. I want to ignore anything between '<' and '>', and I also want to ignore anything between '<style>' and '</style>'. Sorry for not being clearer the first time.

To give a little more insight. I have created a tool to create a list of terms or words that you would want to replace with other custom terms. Since it is an area that can be used by an end user, I want to avoid any display issues. Example: if someone happens to put the word "table" in with a replacement word of "desk", it currently replaces the "<table" with "<desk" thus causing a display issue to the client.

So, my hope was to ignore anything between the '<' and '>', and also '<style>' and '</style>'. This would negate any possibility of a display issue.

I hope this explanation helps, it's fairly difficult to explain. I modified the script you posted, and created two parts, one to change the tag names, commit my change to all the terms in my logic, and then change all of the tag names back to normal. This seems to be working okay at the moment, but it leaves attribute names in tact, like "name, id, value, border, etc..." It just seems to me like there should be an easier way to do this with regex, but I could be wrong.

Thanks,
Dan

Reply With Quote
  #9  
Old March 19th, 2008, 02:06 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,475 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 7 m 51 sec
Reputation Power: 42
Yes I follow what you're trying to do, but this one goes beyond my simple regex skills I'm afraid. I'd speculate that this one is going to get rather complicated.

Reply With Quote
  #10  
Old March 19th, 2008, 02:22 PM
nhrrdan nhrrdan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Hampshire
Posts: 61 nhrrdan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 19 m 22 sec
Reputation Power: 5
Send a message via AIM to nhrrdan Send a message via Yahoo to nhrrdan
Quote:
Originally Posted by kiteless
Yes I follow what you're trying to do, but this one goes beyond my simple regex skills I'm afraid. I'd speculate that this one is going to get rather complicated.


Thank you for your input, I will see if I can hunt down a regex expert to help me out. For now I will leave it with the tag renaming, odds are there won't be any issues, but you never know what a uneducated user might do. I am just trying to think further down the road here.

Thanks again,
Dan

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > RegEx Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway