I am trying to match a word and replace with a capitalised version, and I don't understand why the word is not being seen?
I have used:
Which I add to a dictionary as key and value, with the regex being the key.
My understanding, and all my reading seems to suggest, that this will search through a string looking for a non-word character, then an 'o' and then an 'r' and if it then finds a non-word character after it matches those two, it will consider that a full match.
I do a check to see if the key exists in the string so as to avoid an exception error:
Item is the phrase: "ConsKa or Conske"
The KeyValuePair does not match the @"\bor\b" just skips right over it.
I don't really understand why it isn't matching?
There is no issue with the dictionary, nor the Linq, as those terms where I have not had to use Regex (characters that never appear in the middle of a word) are found and replaced with no issue. It is when I come to deal with characters that could appear in the middle of a word where I want to rely on the regex that this issue arises.
I have used:
C#:
@"\bor\b", "OR"
Which I add to a dictionary as key and value, with the regex being the key.
My understanding, and all my reading seems to suggest, that this will search through a string looking for a non-word character, then an 'o' and then an 'r' and if it then finds a non-word character after it matches those two, it will consider that a full match.
I do a check to see if the key exists in the string so as to avoid an exception error:
C#:
foreach (KeyValuePair<string, string> entry in dict)
{
if (item.Contains(entry.Key))
{
var outPut2 = Regex.Replace(item, string.Join("|", dict.Keys.Select(k => k.ToString()).ToArray()), m => dict[m.Value]);
strOut.Text += outPut2 + Environment.NewLine;
}
}
Item is the phrase: "ConsKa or Conske"
The KeyValuePair does not match the @"\bor\b" just skips right over it.
I don't really understand why it isn't matching?
There is no issue with the dictionary, nor the Linq, as those terms where I have not had to use Regex (characters that never appear in the middle of a word) are found and replaced with no issue. It is when I come to deal with characters that could appear in the middle of a word where I want to rely on the regex that this issue arises.