Loki
Loki

Reputation: 77

Regular expression matching sentence

I need regular expression which would match a sentence in a text file. By sentence I mean a string which starts with capital letter and ends with a period. So far I've came up with this:

[A-Z]+[A-Za-z0-9_,"#;.() \t]+[.]$

It's kind of working, but there's a little problem. When there are few sentences in one line, it sums them up and count as one. Any tips how to fix it?

Upvotes: 0

Views: 97

Answers (2)

tenub
tenub

Reputation: 3446

I would extend this to [A-Z][\s\S]+?[.?!]+. "LOOK OUT!!" is a sentence in my book. Also allows for sentences with whitespace between them.

Upvotes: 0

Lorcan O'Neill
Lorcan O'Neill

Reputation: 3393

You could try this regular expression

[A-Z]{1}[^.]*.

Upvotes: 1

Related Questions