We have a test like "This is a bug (solveing) ? & @ # 17066.".
After we modify the test with below logic :
// replace
tags with new line characters
string replaceContent = Regex.Replace(contentText, @"
", "\n");
// add full stop to inner text of an element, if it needs one, to separate from next word when tags removed
replaceContent = Regex.Replace(replaceContent, @"\w(?=\w+>)", @"$0\.");
// remove all tags and leading and trailing space
replaceContent = Regex.Replace(replaceContent, "<.*?>", string.Empty).Trim();
CommonMethods.WordMatchCollection = CommonMethods.WordRegularExpression.Matches(replaceContent);
// match words which are not in tags
string pattern = @"(?]*?)\b(\w+|\w+['-]\w+)\b(?![^<]*?>)";
string replacement = "$0";
// surround words in text with tags
contentText = Regex.Replace(contentText, pattern, replacement);
return contentText;
The formated test is as follows:-
This is a bug (solveing) ? & @ # 17066.
We want to add Span tags for Speacial character like #, $, @ etc also.
How we can do this.
Thanks in Advanced.
Javeed M ShaikhPosted Oct 27, 2011, 1:18 PM
// match words which are not in tags
string pattern = @"(?]*?)\b(\w+|\w+['-]\w+)\b(?![^<]*?>)";
string replacement = "$0";
// surround words in text with tags
contentText = Regex.Replace(contentText, pattern, replacement);
string pattern2 = @"([!@#?$%^&*()]|(?:[.](?![a-z0-9]+$)))";
contentText = Regex.Replace(contentText, pattern2, replacement);
Nageswararao DhulipallaPosted Oct 27, 2011, 12:44 PM
We need to add span tag for each word as well as speacial characters or single words.
My code is working fine for each words but not for speacial characters.
Input is "This is a bug (solveing) ? & @ # 17066.".
Current Output was:-
This is a bug (solveing) ? & @ # 17066.
Expected output was:-
This is a bug (solveing) ? & @ # 17066.
Javeed M ShaikhPosted Oct 27, 2011, 11:57 AM
I am sorry, but I am not clear on your requirements, can you please be more specific on what is the input and what is the expected output ( also any logic conditions to be checked)