The Solution 1 given by
RDBurmon is good.
As an alternative the following regular expression can be used to search for the alpha numeric words. It first searches for a word with 2 or more alpha numeric characters, then it checks whether at least one digit and at least one character is present in the searched word and only if it is so, the word will be captured as a group.
Further the captured group can be used for replacement. For eg. each of the captured word can be enclosed within <u> and </u> as shown below:
The
Regular Expression
can be tested here
http://regexhero.net/tester/[
^]
string inputText = @"Get 20% Off Your Entire Order & FREE Shipping " +
@"(first time customers only)! Enter coupon code NEW20VISION at checkout." +
@"Limited time offer. NEW20 20VISION New20New20New20Ne20 N2";
MatchCollection alphaNumMatches = Regex.Matches(inputText,
@"(?=\w{2,})(?=\w*\d+)(?=\w*\p{L}+)(\w{2,})",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
foreach(Match match in alphaNumMatches){
if (match.Groups.Count > 0)
Console.WriteLine (match.Groups[1].Value);
}
string replacedText = Regex.Replace(inputText,
@"(?=\w{2,})(?=\w*\d+)(?=\w*\p{L}+)(\w{2,})",
@"<u>$1</u>");
Console.WriteLine (replacedText);