Solved

How would I write a regex in coldfusion to do this

Posted on 2012-03-27
6
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

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…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

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