[thelist] Regex Help

Noah St. Amand noah at tookish.net
Sat Feb 4 00:14:41 CST 2006


Hi,

I'm trying to write a regex to extract the first sentence from a string 
that can be any length, from a few words to multiple paragraphs.

The complicating factors are that the first sentence might include 
periods that don't indicate the end of the sentence (e.g., an email 
address), the first paragraph may be only one sentence long (in which 
case the period I want to target will be followed by a line break rather 
than a space), and there may actually be no period anywhere in the 
string (in which case I'll just take the whole string). What I have so 
far is:

"/^[^\.]*\.\s/"

This works in most cases, but doesn't return anything if the first 
sentence contains a period not followed by a \s. I think I can see why 
this is, but I can't find a syntax to make it work.

I'm using preg_match in PHP if that's at all relevant.

Thanks for any advice,
Noah



More information about the thelist mailing list