Pritesh Chhunchha Pritesh Chhunchha - 3 months ago 17
C# Question

Regex to match a sentence end with full stop(.) ignore decimal point

I want to match a sentence stating with specific word and end with full stop. A sentence could contain a decimal number.

Example

This is closely followed by Indora where 2,194 motorists were fined. South, East, West and North zones of city traffic police have booked 1,514, 983 and 594.00 motorists respectively. Interestingly, the biggest chunk of motorists booked was from MIDC area where 2,297 were penalized for using shrill horns.

I want to match the line in bold
If i use the regex below

south[^\.]*\.


It will match

South, East, West and North zones of city traffic police have booked 1,514, 983 and 594.

How can I ignore decimal number from a sentence to match a sentence.

Answer

You can add a look-ahead constraint to allow a digit after the dot:

South(?:[^\.]|\.(?=\d))*\.

Demo