Hi,
I am not sure if I am losing it or there is actually a bug with DocumentTextSearch. I have a document for which I want to find a replace some text. all the text that needs to be replace matches this regular expression {{(.*?)}}. Now the code below works for everything except if the text has a number in it. For example, say I want to match {{COM_LDL}}, then this gets matched perfectly. but if i want to match {{COM_LDL1}} then only {{COM_LDL is matched and the rest is disregarded. Below is the code, can somebody please help?
Thanks,
Roy
DocumentTextSearch search = new DocumentTextSearch(rtb.Document);
List<TextRange> rangesTrackingDocumentChanges = new List<TextRange>();
foreach (var textRange in search.FindAll("{{(.*?)}}")) //find all merge fields
{
TextRange newRange = new TextRange(new DocumentPosition(textRange.StartPosition, true), new DocumentPosition(textRange.EndPosition, true));
rangesTrackingDocumentChanges.Add(newRange); --> this is where the problem happens. if there is a number (COM_LDL1) then newRange.StartPosition.ToString() returns "\"{{COM_LDL\"@0" if there isnt a number then newRange.StartPosition.ToString() works perfectly and returns "\"{{COM_LDL}}\"@0"
}
I am not sure if I am losing it or there is actually a bug with DocumentTextSearch. I have a document for which I want to find a replace some text. all the text that needs to be replace matches this regular expression {{(.*?)}}. Now the code below works for everything except if the text has a number in it. For example, say I want to match {{COM_LDL}}, then this gets matched perfectly. but if i want to match {{COM_LDL1}} then only {{COM_LDL is matched and the rest is disregarded. Below is the code, can somebody please help?
Thanks,
Roy
DocumentTextSearch search = new DocumentTextSearch(rtb.Document);
List<TextRange> rangesTrackingDocumentChanges = new List<TextRange>();
foreach (var textRange in search.FindAll("{{(.*?)}}")) //find all merge fields
{
TextRange newRange = new TextRange(new DocumentPosition(textRange.StartPosition, true), new DocumentPosition(textRange.EndPosition, true));
rangesTrackingDocumentChanges.Add(newRange); --> this is where the problem happens. if there is a number (COM_LDL1) then newRange.StartPosition.ToString() returns "\"{{COM_LDL\"@0" if there isnt a number then newRange.StartPosition.ToString() works perfectly and returns "\"{{COM_LDL}}\"@0"
}