2010-11-29, 02:58 PM
Russt Wrote:If you're not restricted to the regex itself, what you could do is iterate through all matches, adding them to a set. Then convert it to a list. Does not preserve order, though.This is the best way of doing it. If you need to preserve order, use an ordered set data structure.
Fiel Wrote:You'd think a powerful parser like regex would be able to return only unique strings. I guess there's no management of that.
I know I could do...
list(set((\d+\s)))
But I was just wondering if there was a way to do this just through regex.
Russt Wrote:There may be; I don't know it all that well (more familiar with the, less featureful Lua pattern matching). Question is, why would you need one?
Fiel Wrote:Because regex is in C and therefore runs much faster than python methods of doing it.
Iterating through the matches and inserting each match into a set will not take much more time than the regex alone. Go ahead, try it.


