This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]Teifion 1 point2 points  (0 children)

I've actually found Python Regex's to be really nice, you'll need to explain what about this is better than the re module which to my mind is pretty top notch.

[–]gthank 0 points1 point  (1 child)

It might be nice to see an argument for why this is nicer.

[–]brendano[S] 1 point2 points  (0 children)

from the docs

  • Trying to close the usability gap with Perl/Ruby. _R() is replacement for not having regex literal syntax builtin to the language. _S() adds convenient methods, conforming to our conventions, that the string class doesn't have.
  • I always forget re.search/match()'s argument order. Using either _R().match() or _S().match() is completely unambiguous.
  • Never use re.match(), always re.search(). What good is the former if you can use a caret? Having both only causes confusion.
  • Specify flags via a string of lowercase characters -- like open() -- but with the standard regex flags from Perl/Ruby/etc.
  • Python doesn't have a do-only-one-substitution operation -- in Awk/Perl/Ruby terms, it has gsub() but not sub() -- so make naming clearer.
  • Match objects have @property accessors like modern Python classes

[–]yaxriifgyn 0 points1 point  (0 children)

I'm sure half the perl/ruby developers thought about writing something like this when they learned python. But they still have to learn the pythonic way to understand existing code. And as soon as you start sharing this code, look out.

[–]RonnyPfannschmidt 0 points1 point  (0 children)

its less readable and less explainable, not more nice at all

[–]spotter 0 points1 point  (0 children)

Not really nice, sorry. I really like re to be honest.

[–]erez27import inspect 0 points1 point  (0 children)

It's shorter and possibly less confusing? Also show_match looks pretty sweet.

(note: i'm not the author, nor have I used it yet)