+ 2
count instead of max
Hello, shouldn't the right definition in the course (Regular Expressions -> Introduction -> Search&Replace) be def re.sub(pattern, repl, string, count) rather than the mentioned def re.sub(pattern, repl, string, max)? If not, may I kindly ask you to explain why? Thanks for checking!
4 odpowiedzi
+ 2
The easiest way to work with it is to write re.sub(..., 1) if you want to replace the first pattern. But you are right, it works with count=1 instead of max=1
+ 1
The mentioned "max=0" is correct.
re.sub(...) doesn't count how often you replace a pattern. The max value can be used to set the maximal number of patterns to be replaced. If max=0, all patterns are replaced
0
Thanks for your reply. When using max the code shows an error message. Replacing max with count works. That's what confuses me. Have you checked the code in the course example?
0
Thanks. I think I'll use the shorter version :-)