REGEX Help - should be easy for you!

Hello, I am using this REGEX to capture the first group of characters before a period, questionmark or exclamation point. I want to broaden this to include a dash surrounded by spaces such as " - " , what say you?

Here's what I have:
/^([^.!?]*[\.!?]+){0,1}/

Open in new window



Thank you!
EffinGoodAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
/^(.*?([.!?]| - )+)/
0
EffinGoodAuthor Commented:
Hi, that does not work at all. :(
0
ozoCommented:
In what way does it not work?
<?php
if (preg_match("/^(.*?([.!?]| - )+)/", "I want to broaden this to include a dash surrounded by spaces such as  -  , what say you?", $matches)) {
  echo "Match was found <br />";
  echo $matches[0];
}
?>
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

EffinGoodAuthor Commented:
Thanks for your help.

I wanted to capture the match and your regex didn't seem to capture anything. Sorry, im no good at regex.
0
ozoCommented:
How did you attempt to capture the match?
0
EffinGoodAuthor Commented:
Thanks again, here's my entire function:

function limit_sentence($text, $limit)
{
    preg_match('/^([^.!?]*[\.!?]+){0,'.$limit.'}/', $text, $abstract);
    return $abstract[0];
}

Open in new window

0
ozoCommented:
function limit_sentence($text, $limit)
{
#    preg_match('/^([^.!?]*[\.!?]+){0,'.$limit.'}/', $text, $abstract);
    preg_match('/^(.*?([.!?]| - )+){0,'.$limit.'}/', $text, $abstract);
    return $abstract[0];
}
echo limit_sentence("I want to broaden this to include a dash surrounded by spaces such as ' - ' , what say you?", 1);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EffinGoodAuthor Commented:
Thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.