[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How would I write a regex in coldfusion to do this

Posted on 2012-03-27
6
Medium Priority
?
346 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 400 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 400 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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 52

Accepted Solution

by:
_agx_ earned 1200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

873 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