Link to home
Start Free TrialLog in
Avatar of EffinGood
EffinGoodFlag for United States of America

asked on

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!
Avatar of ozo
ozo
Flag of United States of America image

/^(.*?([.!?]| - )+)/
Avatar of EffinGood

ASKER

Hi, that does not work at all. :(
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];
}
?>
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.
How did you attempt to capture the match?
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

ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!