Link to home
Start Free TrialLog in
Avatar of handypam
handypam

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of shanikawm
shanikawm
Flag of Sri Lanka 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
Avatar of noam_dz
noam_dz

preg_split("/([.?\n])/", $paragraph, -1, PREG_SPLIT_DELIM_CAPTURE); or something like that. If I understand your question.
SOLUTION
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
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

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

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

/([\w\s]+)[!\?]?/ -> with capturing groups
noam_dz: That regex does not detect the <br/> as requested in the question.
Avatar of handypam

ASKER

thanks for your help experts....