Below the first Debug returns ‘unsbuscrib”d and the second returns unsbuscrib”d. The difference is the leading ‘.
What I would like is for both to return unsbuscrib”d.
string textText = " 'unsbuscrib''d' ";
Regex rTest = new Regex(@"\b(ab)|(['\w]+)\b");
if (rTest.IsMatch(textText))
{
Debug.WriteLine(rTest.Match(textText).Value);
}
rTest = new Regex(@"\b(['\w]+)\b");
if (rTest.IsMatch(textText))
{
Debug.WriteLine(rTest.Match(textText).Value);
}
The fix was @”\b((ab)|([‘\w]+))\b” thanks to Guffa
That’s because the first regular expression matches
\b(ab)or(['\w]+)\b.It will include the apostrophe at the beginning, as it uses the second part, where there is no requirement of a word boundary at the beginning.
The second regular expression requires a word boundary at the beginning, and there is no word boundary between the space and the apostrophe. The first word boundary is between the apostrophe and the letter
u.