Cold Fusion Regular Expression

Hi,
I have this RegEx for Cold Fusion
<cfset search.szQuickValue=REReplaceNoCase("#search.szQuickValue#","Ave.","Ave")>

I use it for when people put in an address and include a period (even though they are not supposed to). So "Ave." will translate to "Ave".
However, I'm seeing that it's also matching if "Ave" is inside of a word, say the word "Brookhaven", it's turning it into "BrookhAve". Not what I want. How can I modify this RegEx to match exactly "Ave." with the period?
Thanks!
Nacht
LVL 1
nachtmskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan CraciunIT ConsultantCommented:
<cfset search.szQuickValue=REReplaceNoCase("#search.szQuickValue#","Ave\.","Ave")>

Open in new window

"." means "any character", you need to escape it to mean "."

HTH,
Dan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
_agx_Commented:
Edit  - never mind. Too slow :)

(no points... I don't have an answer)

I was going to suggest using a word boundary ie "\b", but I *think* periods are considered boundary markers too. Since it is also part of the text you want to replace, not sure if that will work.  

Side note, periods have a special meaning in regex's. So your expression is actually replacing any character following "Ave" - not just a literal period.

<!--- test code --->
<cfset arr = ["ABC Ave.", "ABC Ave. NY", "Test Ave.nue A", "Ave. 123","Ave.", "Avec Test"]>

<cfloop array="#arr#" index="search.szQuickValue">
<cfset newValue =REReplaceNoCase(search.szQuickValue,"Ave.","Ave")>
<cfset writeOutput("<br>old=#search.szQuickValue# || new = #newValue#")>
</cfloop>

Open in new window

nachtmskAuthor Commented:
Thanks! Rookie Mistake. I actually knew that from RegEx in perl, but it just didn't occur to me.
Thanks!

I have one more, if you have a sec.

<cfset search.szQuickValue=REReplaceNoCase("#search.szQuickValue#","Port Jeff","Port Jefferson")>

If someone types in "Port Jefferson", the result I get back is: Port Jeffersonerson, because it's matching the "Port Jeff".
What I'm trying to do is if someone abbreviates and searches for "Port Jeff" they will get Port Jefferson (which this regEx actually does go. But as i said, if they search "Port Jefferson" it all gets messed up. Possible?
Thanks!
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Dan CraciunIT ConsultantCommented:
<cfset search.szQuickValue=REReplaceNoCase("#search.szQuickValue#","Port Jeff$","Port Jefferson")>

Open in new window

This should only replace if Jeff is immediately followed by the end of string.
What you're doing is infinite recurrent replace: on every replace an additional "erson" is added.
_agx_Commented:
(no points...)

Same thing will happen with "Ave.". Though less likely it'll be part of a word due to the period. Sounds like you do need word boundary markers ie "\b", since the phrase might occur anywhere within the string. I'll leave that to the Regex folks though :)
nachtmskAuthor Commented:
Thanks Dan for the second solution as well as the first. Both work great.

Thanks _agx_ for your input as well!

Nacht
Dan CraciunIT ConsultantCommented:
You're welcome.

Glad I could help!
_agx_Commented:
> if Jeff is immediately followed by the end of string.

@nachtmsk - Welcome.  Reason for suggesting boundary markers was because I thought the key text could be anywhere within the string.  If you're sure it's always   at the end of the string, well .. that makes life much simpler ;-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.