Click to See Complete Forum and Search --> : Problem with Regex


underwar
March 3rd, 2003, 09:01 PM
I'm writing the following statement:

string sValue = @"(r11) , ";
string res = Regex.Match(sValue, @"[^,(\s)]+(\s)*,*(\s)*", RegexOptions.Compiled).Value;
Console.WriteLine(res););


I wish to get the string "(r11)" without the comma and the spaces.
Yet I get the string "r11" without the parentheses too.
What I'm doing wrong?

pareshgh
March 4th, 2003, 02:09 AM
if you know that r11 is a fix then
you could try

string sValue = @"(r11) , (r11) ooioi0w0";
Regex r = new Regex(@"\(r11\)",RegexOptions.Compiled);
MessageBox.Show(r.Match(sValue).Value);


-Paresh

underwar
March 4th, 2003, 05:54 AM
The idea is to remove the whitespaces and the comma after the expression.
(r11) is only an example

pareshgh
March 6th, 2003, 03:50 PM
did you do your homework :-)
:D ;)

underwar
March 9th, 2003, 05:22 PM
Got your message. Will try to come with less "homework" questions :)

pareshgh
March 10th, 2003, 12:06 PM
u r becoming smarter day by day
hmm
;)