I wonder if there is an easy way to check if two strings match by excluding certain characters in the strings. See example below.
I can easily write such a method by
Sorry but I think either regex, or replacing the "wildcard" characters with a common character are going to be your best solution. Basically, the answers that you stated you didn't want to receive.
I found myself having the same requirements, the solution I used was based on the String.Compare method:
String.Compare(str1, str2, CultureInfo.InvariantCulture, CompareOptions.IgnoreSymbols)
You can of course test the regex w/out substitution:
[a-zA-z]{3}.[a-zA-z]{3}
Seems like a common use for regex, so why the avoidance?
Not sure if this helps:
The Damerau-Levenshtein distance is one of several algorithms dealing with fuzzy string searching.
The DLD between "ABC-EFG" and "ABC*EFG" is 1—"the minimum number of operations needed to transform one string into the other, where an operation is defined as an insertion, deletion, or substitution of a single character, or a transposition of two characters."
Of course this algorithm would also return 1 for the two strings "ZBC-EFG" and "ABC-EFG"—possibly not what you are looking for.
An implementation of the DLD, in Python, from http://paxe.googlecode.com/svn/trunk/paxe/Lib/Installer.py :
def dist(s1, s2):
d = {}
lenstr1 = len(s1)
lenstr2 = len(s2)
for i in xrange(-1,lenstr1+1):
d[(i,-1)] = i+1
for j in xrange(-1,lenstr2+1):
d[(-1,j)] = j+1
for i in xrange(0,lenstr1):
for j in xrange(0,lenstr2):
if s1[i] == s2[j]:
cost = 0
else:
cost = 1
d[(i,j)] = min(
d[(i-1,j)] + 1, # deletion
d[(i,j-1)] + 1, # insertion
d[(i-1,j-1)] + cost, # substitution
)
if i>1 and j>1 and s1[i]==s2[j-1] and s1[i-1] == s2[j]:
d[(i,j)] = min (d[(i,j)], d[i-2,j-2] + cost) # transposition
return d[lenstr1-1,lenstr2-1]
No, there is nothing in the framework itself that can do this.