Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

.NET Regex for full stop at the end of a sentence

I want to match a full stop at the end of each sentence in a paragraph of text.

There must be atleast 3 words before the fullstop(.)

This is to ensure only full stops at the end of sentences are counted. Periods in Microsoft v 3.2.1 are skipped! Please note that the words may not necessarily contain latin characters. I plan to use in other languages so we can't use [a-Z] here!

What i tried .+s+.+s+.+[.] But this selects the whole sentence!

Probably one can use a if else construct? if .+s+.+s+.+[.] is found, select the dot or else don't. Is it possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ok. Here's a go at it:

(?:(?:s|^|.)[^sd.]+){3}(.)

Expl.: (Non capturing) find a space, full stop or start of line followed by any number (at least one) of characters that isn't a space, digit or a full stop. Repeat this 3 times. Then capture a full stop :D Done!

Check it out here.

Regards


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...