?
Solved

ASP - Regex to get sentences from block of text

Posted on 2009-02-12
2
Medium Priority
?
576 Views
Last Modified: 2012-05-06
Hi

I have stored some reviews and need to take a snippet of them, ideally I was looking for a way to extract the first 2 sentences from each block of text.

I can manage to extract the first sentence using the code below, but cant get the 2nd for some reason

please can you help and advice
dim regEx, replacementstring
Set regEx = New RegExp
regEx.IgnoreCase = true
regEx.Global = false
regEx.Pattern = "[^\.]+[^\.]"
Set Matches  = regEx.Execute("I have never before so to be fair I cannot compare this with other products on the market. I love styling - it looks like a ray gun sci-fi movie! The suction of this size and I have found the compact size means you are more inclined to use it. It quickly so for example if you were to vac all the small bits in a double size room such as my kitchen diner it expect to do the whole house in one go! I also doubt that it would adequately clean your car interior on one charge. use from one charge which takes about three hours. I think this a backup for your main vac and saves hauling a heavy machine out for a small clean up. It s a shame they don t provide a such as you would get with a drill.")
For Each Match in Matches   ' Iterate Matches collection.
    Response.Write(Match.Value)
Next

Open in new window

0
Comment
Question by:sparky74
2 Comments
 
LVL 28

Accepted Solution

by:
sybe earned 2000 total points
ID: 23630905
Why not split the text on the period (".") and use the first two elements of the resulting array?
<%
 
s = "I have never before so to be fair I cannot compare this with other products on the market. I love styling - it looks like a ray gun sci-fi movie! The suction of this size and I have found the compact size means you are more inclined to use it. It quickly so for example if you were to vac all the small bits in a double size room such as my kitchen diner it expect to do the whole house in one go! I also doubt that it would adequately clean your car interior on one charge. use from one charge which takes about three hours. I think this a backup for your main vac and saves hauling a heavy machine out for a small clean up. It s a shame they don t provide a such as you would get with a drill."
 
a = Split(s, ".")
SELECT CASE Ubound(a)
    CASE -1
        ' no elements
        result = "" 
 
    CASE 0
        ' one element
        result = a(0) 
 
    CASE Else
        ' two or more elements
        result = a(0) & "." & a(1) 
 
END SELECT
%>

Open in new window

0
 

Author Closing Comment

by:sparky74
ID: 31546098
thank you sybe. I had not used the split function before. This is great and very easy to understand and works a treat!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

840 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