Solved

How would I write a regex in coldfusion to do this

Posted on 2012-03-27
6
339 Views
Last Modified: 2012-06-27
How would I write a regex in Coldfusion that would search for any "." period characters that appear within brackets and then replace those periods with a space.

For example:

Yada yada yada (my data. yoho. ho) yaya yaya.

I want to turn this into:

Yada yada yada (my data   yoho   ho) yaya yaya.

The reason is that I want to parse a paragraph into its individual sentences and I'm using the period at the end of each sentence as a delimiter.

But some paragraphs have content in brackets and some of that content contains abbreviations followed by a period which have nothing to do with the end of the sentence.

Or maybe there is a smarter way to do this.

Hope you can help

Thx
0
Comment
Question by:bigmikey88
6 Comments
 
LVL 16

Assisted Solution

by:Gurpreet Singh Randhawa
Gurpreet Singh Randhawa earned 100 total points
ID: 37775142
you can do this with simple replace functionality:

<cfset urstring = "Yada yada yada (my data. yoho. ho) yaya yaya.">

<cfset strRemovePeriods = Replace("#urstring#","."," ","ALL")>

<cfdump var="#strRemovePeriods#">

it will show ur string as periods replaced with spaces
0
 

Author Comment

by:bigmikey88
ID: 37777202
But I don't want to remove the periods that mark the end of a sentence.  Just want to remove other periods - which show up between brackets ( )
0
 
LVL 7

Assisted Solution

by:micropc1
micropc1 earned 100 total points
ID: 37778187
Not sure how you would do that that with CF's regex functions. You may need to create a UDF to do some string parsing like follows... (this will only work for the first set of parens)

<cfset myStr = "Yada yada yada (my data. yoho. ho) yaya yaya.">
<cfset indexParen1 = find("(", myStr, 1)>
<cfset indexParen2 = find(")", myStr, indexParen1)>

<!---if parens exist and are in the correct order--->
<cfif indexParen1 NEQ 0 AND indexParen2 NEQ 0 AND indexParen2 GT indexParen1>
	<cfset myStr =left(myStr, indexParen1 - 1) & replace(mid(myStr, indexParen1, indexParen2 - indexParen1 + 1), ".", " ", "all") & right(myStr, len(myStr) - indexParen2)>
</cfif>

<cfoutput>#myStr#</cfoutput>

Open in new window

0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 52

Accepted Solution

by:
_agx_ earned 300 total points
ID: 37778273
(no points ..)

Mike - Might be possible, but you should really add the regex zone to the question. A regex guru could tell you if it's possible with lookaheads.
0
 

Author Closing Comment

by:bigmikey88
ID: 37778346
I will repost in the regex section

Also going to the tech bookstore to find a good book in Regex.

Thx all
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37778421
Mike - Appreciate the points, but in this case they should go to the other 2 experts that unlike me - provided actual code! ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question