0

Hello,

I'm totally out of luck with creating a working patternt to match for my preg_match.
What I would like to do is, create a pattern that will match sentenses in a bunch of text..

It should recognize a word that has a capital letter and take it as the start of sentese and then get all words till it hits . ? or !. so the patterns should contain A-Z a-z 0-9 , " ' and stop when it hits . ! or ? .. any help creating such pattern would be appriciated.

Thanks, Dusan

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by radovanov
0

This matches a sentence as you've defined it. It will also match across multiple lines:

<?php
$rx = '/\b[A-Z].*[\.?!]/msU';
$testPhrases = "Alas, can I put time in a bottle? The quick brown \nfox jumps over the lazy dog.  Sally \nsells seashells by the seashore.";
$arFound = array();

$count = preg_match_all($rx, $testPhrases, $arFound);

print_r($arFound);
?>
0

Thanks a lot with your help, that is just what I was trying to do, it works perfect!

Thanks madCoder

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.