Learn how to a build a cloud-first strategyRegister Now


PHP preg_split by sentence

Posted on 2006-05-13
Medium Priority
Last Modified: 2012-06-21
I have found an example of preg_split to split by sentence but I can't get it to work.


Now, my sentences in this case will all end in either period-quote-space OR questionmark-quote-space OR period-space OR questionmark-space OR exclaimationmark-space or exlamationpoint-quote-sapce

I don't get the above.  

What's the <=


Question by:cglenn3932
  • 4
LVL 25

Expert Comment

ID: 16673899
<= is part of the positive lookahead, and ?= is part of positive lookbehind.

I'll try and come up with a better regex for this (which will hopefully work as well) ;)

LVL 25

Expert Comment

ID: 16673940
This seems to work for me:

LVL 25

Expert Comment

ID: 16673941


Author Comment

ID: 16675312
What is a positive lookahead, this Perl syntax is quite new to me.

I can't get yours to run.  I can get:


to run, so the err must be ....?  I am running PHP 4.X, does that matter?
LVL 25

Accepted Solution

InteractiveMind earned 2000 total points
ID: 16677144
positive lookahead is a way of saying "get the text that precede's some other text, but don't include that other text". And positive lookbehind is the same thing, but for a string _after_ some other text, rather than before.

The regex I posted above works fine with my Java program which I tested it with; I've never really had any problems porting Java-compatible regex's to PHP before, but will have a play with it, and try and get something which is PHP-compatible..

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Six Sigma Control Plans

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question