Regex to find end of paragrphs -
i'm parsing text , paragraph breaks have been removed. need regex locate sentence ends in punctuation (period, question, etc) , there no space before next sentence starts. take , insert 2 linebreaks. unfortunately regex have far greedy , snagging on urls.
preg_replace('/(?<!\.)\.(?!(\s|$|\,|\w\.))/', '.<br/><br/> ', $string);
example text:
approved source xxxx xxx.the solicitation xxx , available @ link provided in notice. see http://www.mysite.com. hard copies of solicitation not available. specifications, plans, or drawings not available.all responsible sources may submit quote which, if timely received, shall considered.quotes must submitted electronically.
final desired result:
approved source xxx xxxx.
the solicitation xxx , available @ link provided in notice. hard copies of solicitation not available. see http://www.mysite.com. specifications, plans, or drawings not available.
all responsible sources may submit quote which, if timely received, shall considered.
quotes must submitted electronically.
thanks
(?<!w{3})[\.\?](?=\s)(?!com)
assuming url
s start/end www.
, .com
, prevent matching, while retaining match on .
, ?
have non-whitespace after them. you'll have replace match .<br><br>
though, not <br><br>
.
Comments
Post a Comment