CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2003
    Location
    Israel
    Posts
    102

    Problem with Regex

    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?

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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

  3. #3
    Join Date
    Feb 2003
    Location
    Israel
    Posts
    102
    The idea is to remove the whitespaces and the comma after the expression.
    (r11) is only an example

  4. #4
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    did you do your homework :-)

  5. #5
    Join Date
    Feb 2003
    Location
    Israel
    Posts
    102
    Got your message. Will try to come with less "homework" questions

  6. #6
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    u r becoming smarter day by day
    hmm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured