PHP preg_split by sentence

Posted on 2006-05-13
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
    LVL 25

    Expert Comment

    <= 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

    This seems to work for me:

    LVL 25

    Expert Comment



    Author Comment

    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

    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..

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    A short article about a problem I had getting the GPS LocationListener working.
    A short article about problems I had with the new location API and permissions in Marshmallow
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    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 …

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now