We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

ASP - Regex to get sentences from block of text

Medium Priority
596 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

Comment
Watch Question

Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
thank you sybe. I had not used the split function before. This is great and very easy to understand and works a treat!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.