James
James

Reputation: 429

Regular Expression spaces and words

I'm pretty new with regular expressions. I'm trying to write a regular expression for a space followed by the word "IN" followed by another space.

So basically " IN ". I will eventually do a case insensitive split with it.

Regex regex = new Regex(*REG EX*, RegexOptions.IgnoreCase);
string[] parts = regex.Split(strValue);

Upvotes: 0

Views: 66

Answers (3)

Oerk
Oerk

Reputation: 158

This should do:

        Regex regex = new Regex(@"\s{1}IN\s{1}");
        string[] split = regex.Split(input);

Upvotes: 0

sam
sam

Reputation: 969

Your *REG EX* should be " IN ".
(Seriously, its " IN ")

Regex regex = new Regex(" IN ", RegexOptions.IgnoreCase);

In case, if you have other whitespace characters i.e., other than space(), you can always use Juan's solution("\s+IN\s+"). Here, \s means any whitespace character.

Upvotes: 1

JuanR
JuanR

Reputation: 7783

Try this:

"\s+IN\s+"

Make sure to ignore case.

Upvotes: 2

Related Questions