Solved

How would I write a regex in coldfusion to do this

Posted on 2012-03-27
6
335 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 15

Assisted Solution

by:myselfrandhawa
myselfrandhawa 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now