Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex - Is this possible?
#13
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. Sad

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.

[Image: premature_optimization.jpg]
Reply


Messages In This Thread
Regex - Is this possible? - by Fiel - 2010-11-27, 11:15 PM
Regex - Is this possible? - by Dusk - 2010-11-27, 11:24 PM
Regex - Is this possible? - by Fiel - 2010-11-27, 11:24 PM
Regex - Is this possible? - by Dusk - 2010-11-27, 11:30 PM
Regex - Is this possible? - by Russt - 2010-11-27, 11:34 PM
Regex - Is this possible? - by Fiel - 2010-11-27, 11:34 PM
Regex - Is this possible? - by Russt - 2010-11-27, 11:39 PM
Regex - Is this possible? - by Fiel - 2010-11-27, 11:42 PM
Regex - Is this possible? - by Dusk - 2010-11-28, 12:46 AM
Regex - Is this possible? - by Russt - 2010-11-28, 01:09 AM
Regex - Is this possible? - by Nikkey - 2010-11-28, 05:39 PM
Regex - Is this possible? - by Fiel - 2010-11-28, 06:14 PM
Regex - Is this possible? - by Spaz - 2010-11-29, 02:58 PM
Regex - Is this possible? - by Fiel - 2010-11-29, 03:07 PM
Regex - Is this possible? - by GummyBear - 2010-12-07, 12:29 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)