EffinGood
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:
Thank you!
Here's what I have:
/^([^.!?]*[\.!?]+){0,1}/
Thank you!
/^(.*?([.!?]| - )+)/
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];
}
?>
<?php
if (preg_match("/^(.*?([.!?]|
echo "Match was found <br />";
echo $matches[0];
}
?>
ASKER
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.
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?
ASKER
Thanks again, here's my entire function:
function limit_sentence($text, $limit)
{
preg_match('/^([^.!?]*[\.!?]+){0,'.$limit.'}/', $text, $abstract);
return $abstract[0];
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!