preg_match_all expression help

Hi experts

I have regular expression for in my pregmatch below.
What i am trying to do it to add the <br/> to the expression so that i can match on that aswell to produce the follow

1:Stop!
2:In the name of love?
3:Before you<br/>
4:break my heart

But as you guessed I CANT DO IT :( urghhhhhhhh

can anyone help?

:D

$paragraph = "Stop! In the name of love? Before you<br/>break my heart";
preg_match_all("# ?([a-z ]+[\.\?!])#i",$paragraph,$sentance);

Open in new window

handypamAsked:
Who is Participating?
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.

shanikawmCommented:
Try this,

This prints,

Array
(
    [0] => Array
        (
            [0] => Stop!
            [1] =>  In the name of love?
            [2] =>  Before you<br/>
            [3] => break my heart
        )

    [1] => Array
        (
            [0] => Stop!
            [1] => In the name of love?
            [2] => Before you<br/>
            [3] => break my heart
        )

)
<?
$paragraph = "Stop! In the name of love? Before you<br/>break my heart";
preg_match_all("# ?([a-z ]+(?:[\.\?!]|(?:<br/>))*)#ui",$paragraph,$sentance);
//preg_match_all("# ?([a-z ]+([\.\?!]|(<br/>))*)#ui",$paragraph,$sentance);
print_r($sentance);
?>

Open in new window

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
noam_dzCommented:
preg_split("/([.?\n])/", $paragraph, -1, PREG_SPLIT_DELIM_CAPTURE); or something like that. If I understand your question.
0
ollyatstithiansCommented:
This will split the string on ! ? or <br/> and trim any spaces from the start of each string:
$sentence = preg_split('%(?:[!?]|<br ?/?>) ?%i', $paragraph);

Open in new window

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

ollyatstithiansCommented:
Sorry, the delimiters are missing. This:

<?php
header('content-type: text/plain');
$paragraph = 'Stop! In the name of love? Before you<br/>break my heart';
$sentence = preg_split('%(?:(?<=[!?])|(?<=<br/>)) ?%i', $paragraph);
var_dump($sentence);

Open in new window


returns:

array(4) {
  [0]=>
  string(5) "Stop!"
  [1]=>
  string(20) "In the name of love?"
  [2]=>
  string(15) "Before you<br/>"
  [3]=>
  string(14) "break my heart"
}

Open in new window

0
noam_dzCommented:
you can also try this simple regex [\w\s]+[!\?]?

or more php-ish /[\w\s]+[!\?]?/

/([\w\s]+)[!\?]?/ -> with capturing groups
0
ollyatstithiansCommented:
noam_dz: That regex does not detect the <br/> as requested in the question.
0
handypamAuthor Commented:
thanks for your help experts....
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
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.