Alvin’s Blog

June 25, 2009

RegEx: Match word boundaries

Filed under: RegEx — amcbride @ 6:11 pm

// matches “forfeiture” or “52″

System.Text.RegularExpressions.Regex rg = new Regex(@”\bforfeiture\b|\b52\b”, RegexOptions.IgnoreCase);

Match m = rg.Match(“forfeiture 52 dkjf 520 foooj”);

while (m.Success)
{
string s = m.ToString();
m = m.NextMatch();
}

Blog at WordPress.com.