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
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);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
preg_split("/([.?\n])/", $paragraph, -1, PREG_SPLIT_DELIM_CAPTURE); or something like that. If I understand your question.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, the delimiters are missing. This:
returns:
<?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);
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"
}
you can also try this simple regex [\w\s]+[!\?]?
or more php-ish /[\w\s]+[!\?]?/
/([\w\s]+)[!\?]?/ -> with capturing groups
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.
ASKER
thanks for your help experts....