Simple regexp question

M

Marko

I have a very tiny problem with regexp and im totally frozen..
If i have several sentences of text, how can i get it out (for
example) first two sentences? Assuming that those sentences can end
with dot ("." only one or more (".." or "..."), question mark ("?") or
exclamation mark ("!").

Thanks for help.
 
G

gnari

Marko said:
I have a very tiny problem with regexp and im totally frozen..
If i have several sentences of text, how can i get it out (for
example) first two sentences? Assuming that those sentences can end
with dot ("." only one or more (".." or "..."), question mark ("?") or
exclamation mark ("!").

split /\.+|\?|!/;

gnari
 
T

Tad McClellan

Marko said:
If i have several sentences of text, how can i get it out (for
example) first two sentences? Assuming that those sentences can end
with dot ("." only one or more (".." or "..."), question mark ("?") or
exclamation mark ("!").


my @sentences = $text =~ /\s*([^.?!]+[.?!]+)/g;


Will fail with a sentence like

Mr. Marko does Perl.

and many others...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top