views:

93

answers:

3

Hi!

i would like to split a text (using a regex) to a dot followed by a whitespace or a dot followed by new line (\n)

i'm working with c# .Net

Appreciate your answers!

A: 

The regular expression

/\.\s/

Will match a literal . followed by whitespace.

Anon.
There is no literal regular expressions (/.../) in C#.
Guffa
+1  A: 
using System.Text.RegularExpressions;
string[] parts = Regex.Split(mytext, "\.\n|\. "); 
# or "\.\s" if you're not picky about it matching tabs, etc.
Tor Valamo
Thanks! Thanks! Thanks!
Tom
A: 

You don't need a regular expression for that. Just use the overload of string.Split that takes an array of strings:

string[] splitters = new string[] { ". ", ".\t", "." + Environment.NewLine };
string[] sentences = aText.Split(splitters, StringSplitOptions.None);
Guffa