tags:

views:

245

answers:

2

I am splitting words from camel style string.Example

    string str = "winAgainWinBest";
    string r = @"(?=[A-Z])";
    var splitted = Regex.Split(str, r);

I get the result

win
Again
Win
Best

When the string is mixed with special characters how will i remove it and get the words?

I mean string str = "win++Again@@Win--Best\\";

+2  A: 

You could try:

var splitted = Regex.Split(Regex.Replace(str, @"\W+", ""), @"(?=[A-Z])");

\W is a shorthand for [^\w] (which equals: [^0-9a-zA-Z_]) and therefore matches any character except a-z, A-Z, 0-9 and _

Bart Kiers
A: 

Try this...

([a-z]+)|([A-Z]+[a-z]+)
Chalkey