locked
Match globally in regex C# RRS feed

  • Question

  • Hi.

    System.Text.RegularExpressions.Match x = Regex.Match(textBox1.Text, @"\b\w+(?='s)\b");

    I want to match the names followed by 's in the textBox1. And here is the code for it. But the problem is it only matches the very first name in the text box and rest other would ignore. In perl language there is a way to match globally using "/g". I want to know if visual C# has something like that to do regex matches globally without doing any modification to this regexpression ?

    Thanks.


    • Edited by string Astro Wednesday, February 19, 2014 10:11 AM a letter is missing
    Tuesday, February 18, 2014 4:51 PM

Answers

All replies

  • I think this should be as easy as calling Regex.Matches instead of Regex.Match.


    PS: The geek in me was secretly hoping this was a actually Math question.  Your typo in the question title got me excited.  ;)

    Tuesday, February 18, 2014 7:27 PM
  • By the way, the expression probably should be adjusted for names like O'Sullivan's.

    Wednesday, February 19, 2014 7:53 AM