symbols for end of sentences

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
varrg
Forum Newbie
Posts: 4
Joined: Wed Jan 16, 2008 1:16 pm

symbols for end of sentences

Post by varrg »

Hi, I need a regex that splits a string on every delimiter that symbolizes the end of a sentence, at the moment used delimiters are:
. ! ? : ; and cause of rest of code requirements I need \n to be a delimiter to.

Also I need those to be able to be repeated, for example: ... should be treated as ONE delimiter not 3 of the same, same goes for ??? !!!!!! :::::: etcetera.

For the difficult part, I need smileys to be delimiters aswell, smileys such as :) :P :p :D :d :s :S =) =D =P =p
basically every common smiley.

At the moment I'm using this regex: /([.\n?!:;]+)+/ which as far as I've tested works fine, although the smileys are not included, I just don't know how to do it. Help!
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: symbols for end of sentences

Post by Kieran Huggins »

maybe try str_replace() and insert a special string (like *|*) as your sentence delimiter, then split on that?

make an array of what you consider delimiters, and a sister array of the same strings ending with your special delimiter. Then explode() on your delimiter.
varrg
Forum Newbie
Posts: 4
Joined: Wed Jan 16, 2008 1:16 pm

Re: symbols for end of sentences

Post by varrg »

yea but this script is meant to be implemented onto alot of things, forum threads, blog posts etcetera and banning | from being used kinda sucks..
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: symbols for end of sentences

Post by Kieran Huggins »

so what's the goal, exactly?
varrg
Forum Newbie
Posts: 4
Joined: Wed Jan 16, 2008 1:16 pm

Re: symbols for end of sentences

Post by varrg »

to split the string at every new sentence (read: not new line)
new sentences being symbolized by the requested delimiters

I am making a quotation system, to add a link before each new sentence that if you click it, you'll come to a page where it shows only that particular sentence
varrg
Forum Newbie
Posts: 4
Joined: Wed Jan 16, 2008 1:16 pm

Re: symbols for end of sentences

Post by varrg »

thanks alot guys, i finally found the right regex, thanks for all the help

#([:;=][|()/{}\[\]<>\\\odpsx]+|[.\n?!:;]+[\s]|[\n])#i
Post Reply