Pattern Matching Given # of Characters and no String Input; use RegularExpressions?
tiissa
tiissa at nonfree.fr
Sun Apr 17 06:07:34 EDT 2005
Synonymous wrote:
> Can regular expressions compare file names to one another. It seems RE
> can only compare with input i give it, while I want it to compare
> amongst itself and give me matches if the first x characters are
> similiar.
Do you have to use regular expressions?
If you know the number of characters to match can't you just compare slices?
In [1]: f1,f2='cccat','cccap'
In [2]: f1[:3]
Out[2]: 'ccc'
In [3]: f1[:3]==f2[:3]
Out[3]: True
It seems to me you just have to compare each file to the next one (after
having sorted your list).
More information about the Python-list
mailing list