?
Solved

How would I write a regex in coldfusion to do this

Posted on 2012-03-27
6
Medium Priority
?
342 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 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
TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
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 …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

765 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