Extracting one word based on special character using Regular Expression in C#

Posted by Jankhana on Stack Overflow See other posts from Stack Overflow or by Jankhana
Published on 2010-04-20T07:31:26Z Indexed on 2010/04/20 7:33 UTC
Read the original article Hit count: 338

Filed under:
|
|

I am not very good at regular expression but want to do some thing like this :

string="c test123 d split"

I want to split the word based on "c" and "d". this can be any word which i already have. The string will be given by the user. i want "test123" and "split" as my output. and there can be any number of words i.e "c test123 d split e new" etc. c d e i have already with me. I want just the next word after that word i.e after c i have test123 and after d i have split and after e i have new so i need test123 and split and new. how can I do this??? And one more thing I will pass just c first than d and than e. not together all of them. I tried

string strSearchWord="c ";
Regex testRegex1 = new Regex(strSearchWord); List lstValues = testRegex1.Split("c test123 d split").ToList();

But it's working only for last character i.e for d it's giving the last word but for c it includes test123 d split.

How shall I do this???

© Stack Overflow or respective owner

Related posts about c#

Related posts about regex